Android 如何将两个微调器均匀对齐?(%50-%50)
我的意思是,我有一条线,我想放两个旋转器在那里,水平。我想把它们放平。但是我没有设置。当我设置为3,3英寸屏幕时,其他屏幕有问题,因为我使用dp。我用什么?线路布局还是相对的?阿娜:我是怎么设置的? 谢谢Android 如何将两个微调器均匀对齐?(%50-%50),android,android-layout,Android,Android Layout,我的意思是,我有一条线,我想放两个旋转器在那里,水平。我想把它们放平。但是我没有设置。当我设置为3,3英寸屏幕时,其他屏幕有问题,因为我使用dp。我用什么?线路布局还是相对的?阿娜:我是怎么设置的? 谢谢 这是IMG来显示我的问题:您可以使用下面的代码来获得与设备无关的动态宽度 DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics
这是IMG来显示我的问题:您可以使用下面的代码来获得与设备无关的动态宽度
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.heightPixels;
int width=metrics.widthPixels;
现在将宽度分成两部分,width=width/2
并动态设置活动中微调器的宽度
spinner.setLayoutParams(new LayoutParams(width,LayoutParams.WRAP_CONTENT));
在线性布局中使用权重和
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5" />
</LinearLayout>
在微调器中使用
android:layout\u weight=“float value here”
。这应该能奏效
请参阅以获取解释 谢谢你的回答。我如何设置代码?你能写一些代码吗。谢谢你的回答,如果我给出2个正确答案,我会在你的答案上打勾,但下面的答案是超级的。你的也是,对不起:(我在4分钟内勾选你的答案
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5" />
</LinearLayout>