设计小部件的宽度和高度以使其在纵向和横向模式下都看起来不错的最佳方法是什么?例如,我试图制作一个简单的注册页面,当他们输入正确格式的信息时,我想在相应的EditText视图旁边显示一个复选框图像。

我的特殊问题是,没有图像复选框,我可以将EditText宽度设置为match_parent,它将以纵向和横向模式扩展到整个屏幕。但是,一旦在ImageView小部件旁边添加了EditText复选框,就必须将EditText的宽度设置为特定的dp值,以便为显示该复选框留出空间。但是现在有了一个特定的dp值,当我将屏幕旋转到横向模式时,EditText视图的宽度比我想要的要短得多。

所以我的问题是,设计小部件的高度和宽度的最佳方法是什么,以使它们在几乎所有手机上看起来都很好,在纵向和横向模式下看起来都很好?我是应该一直为横向模式设计一个单独的布局,还是有一种更聪明的方法来避免这种情况?

最佳答案

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

<EditText
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_weight="2"
     <!-- your stuff here --> />
<ImageView
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_weight="0.5"
    <!-- your stuff here --> />
 />

10-07 19:23
查看更多