Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用变量设置customView的大小_Android - Fatal编程技术网

Android 使用变量设置customView的大小

Android 使用变量设置customView的大小,android,Android,我有一个customm视图,它生成一个弧,我像这样输入了xml <com.example.application.ArcView android:id="@+id/arcView1" android:layout_width="@string/arc_size" android:layout_height="@string/arc_size" android:layout_centerInParent="true" />

我有一个customm视图,它生成一个弧,我像这样输入了xml

<com.example.application.ArcView
        android:id="@+id/arcView1"
        android:layout_width="@string/arc_size"
        android:layout_height="@string/arc_size"
        android:layout_centerInParent="true" />

如何将宽度和高度设置为变量?

您可能想问“如何设置要查看的宽度和高度”

您需要在活动类中引用ArcView的实例,以便在活动的onCreate方法中更加精确,如下所示:

ArcView arcView = (ArcView)findViewById(R.id.arcView1);
之后,根据密度计算宽度和高度,并通过

arcView.setLayoutParams(myLayoutParams);

我怎样才能给它一个精确的值?(我知道ldpi需要170,mdpi 227,hdpi 342)它不接受int作为value@DoubleP90
arcView.setLayoutParams(新的LinearLayout.LayoutParams(arcSize,arcSize))
FYI:通过更改
arcSizeString
值,您不会更改资源中的
arcsize
值。资源是用来使用的,不会被修改。
arcView.setLayoutParams(myLayoutParams);