在Android Studio中,是否有一个XML布局可以自动调整(缩小/放大)视图内容用户界面,以适应不同大小的单个屏幕(即不同的智能手机、平板电脑等)而不是使用LinearLayout和ScrollView的组合来将每个UI组件堆叠在一起?
我通常只做后者,但只是好奇是否有一种布局可以自动检测用户的屏幕大小,并相应地缩小/放大视图内容。
发布于 2018-01-16 12:57:50
发布于 2018-01-16 13:04:01
您应该使用layout_weight属性。
发布于 2018-01-16 13:00:41
您可以使用LinearLayout的weightSum和layout_weight组件。有关详细信息,请查看:
https://developer.android.com/reference/android/widget/LinearLayout.html#getWeightSum()
https://developer.android.com/guide/topics/ui/layout/linear.html
示例:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:weightSum="4">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/black" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="@android:color/darker_gray" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/white" />
</LinearLayout>https://stackoverflow.com/questions/48274215
复制相似问题