保证金dp单位在不同的屏幕上不能正确缩放布局
问题描述:
我有简单的tableLayout,它显示了独立单位dp的问题。保证金dp单位在不同的屏幕上不能正确缩放布局
我想,在我的layout_margin属性 - 在任何设备上的布局将被调整大小没有问题。
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:layout_margin="40dp"
>
<TableRow android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView
android:text="@string/start_login_username"
android:id="@+id/start_login_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/start_login_EditTxt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView
android:text="@string/start_login_password"
android:id="@+id/start_login_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:id="@+id/start_login_EditTxt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="wrap_content">
<Button android:text="@string/start_login_cancel"
android:id="@+id/start_login_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</Button>
<Button
android:text="@string/start_login_login"
android:id="@+id/start_login_ButtonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</Button>
</TableRow>
</TableLayout>
但是,测试这个布局中,我们可以看出,DP是不是在布局利润率这么独立。
下面的截图在三星Nexus(良好级):
下面的截图中LG擎天柱GT 540(差级):
我在*中寻找类似的线程和可能的解决方案,以在任何屏幕上具有正确的比例是:
不使用margin和padding可言,但总使用tableLayout并添加 MOC查看了一些体重,视图之间添加空格(不是因为 污染XML布局的好。无论如何,它看起来很有前途)。
让我自己独立单元的计算和重新调整所有的编程方式(对我来说并不好,因为我都在XML的)
使用不同的布局型动物屏幕(不是一件好事,因为林懒得重建布局为每个我的看法和支持他们)
问题:
我怎样才能解决这个问题,我的布局比例为所有屏幕使用相同的布局?
如何让我的屏幕上的边距工作正确?
您对我的两个解决方案有何看法?这是很好的做法? (特别是第一个)?
感谢
答
只需使用的LinearLayout与权重属性,记得设置宽度=“0dp”如果这是你想要的宽度自动调整。
你的XML应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<TextView
android:text="Your name"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<EditText
android:layout_weight="1"
android:layout_width="0dp"
android:minWidth="80dp"
android:layout_height="wrap_content" />
</LinearLayout>