你好我是 Android 的新手,我的英语不好。我试试 我想将我的布局分成 3 种不同的大小。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView
android:id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="Esto es una mierda de Relative Layout" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2">
<Button
android:id="@+id/btn1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:text="Button" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:text="Button" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
我的代码应显示三列,中间列的大小是侧列的两倍。如果我将所有布局设置为相同的布局权重,它们都会正确显示,但大小相同。
但是,当我将中心列设置为不同的大小值(在布局权重中)时,它会从屏幕上消失。
如何在不同大小的三列中显示我的布局?
如果有人可以帮助我。感谢阅读。
最佳答案
使用这个结构:
<!-- parent layout-->
<LinearLayout
android:weightSum="1">
<!-- children layouts -->
<RelativeLayout
android:weight="0.25"
></RelativeLayout>
<RelativeLayout
android:weight="0.5"
></RelativeLayout>
<RelativeLayout
android:weight="0.25"
></RelativeLayout>
</LinearLayout>
关于android - 百分比布局 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22635633/