我是 android 的新手,想问一下居中实践,我的意思是,例如:
在我说些什么之前,我不知道什么是好的做法,所以...
我可以有一个 LinearLayout
,高度为 match_parent
和 android:layout_marginTop="?attr/actionBarSize"
(顺便说一句,根据 google's material 56dp
).
所以这是一种选择,但是,我看到如果设备真的很长(例如 Galaxy Note 设备),内容会很好地居中,所以我所做的是:
相同的 LinearLayout
但高度为 wrap_content
和 android:layout_gravity="center"
,但是问题例如,这里有一个只有 1 个字段(几乎没有内容高度)的表单,问题是几乎没有任何内容会给您在工具栏和内容之间以及该内容下方留下很多空间。
我的问题: 我想问的是最佳实践,什么是使内容(更大或更小)在多个设备上很好地显示的最佳方法,可能需要多个布局/尺寸,我对此没意见,只是在寻找正确的路径。
最佳答案
还有一个名为RelativeLayout
的 View 组。
你可以这样使用它:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
// here you can use attributes such as `android:layout_below`, `android:layout_above`,`layout_toRightOf`
//to modify and control your items
/>
</RelativeLayout>
关于java - Android,我应该将内容居中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40068643/