Fla*_*lyn 3 android relativelayout android-layout
我正试着RelativeLayouts在屏幕上四个位置,如下图所示.我似乎无法到达任何地方.每个都将包含一个文本标签和一个以象限为中心的按钮.我已经尝试将四个内部放置在适当设置RelativeLayout的alignComponent值,并将alignParent值设置为左/右和上/下.我也尝试了只是alignComponent设置,只是alignParent设置但无济于事.
看起来应该是这样的,

既然你想使用RelativeLayout,最简单的方法是使用垂直和水平支柱(它是不可见的)并将它们用作你四个RelativeLayout孩子的锚点.这种方法肯定比LinearLayout具有权重的嵌套s 更有效.您应该在使用权重嵌套之前阅读此内容LinearLayout.
以上链接的摘录:
布局权重需要两次测量窗口小部件.当具有非零权重的LinearLayout嵌套在具有非零权重的另一个LinearLayout内时,则测量数量呈指数增长.
因此,对于使用RelativeLayout带有struts的 s ,您的XML可能是这样的:
<RelativeLayout 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"
tools:context="${relativePackage}.${activityClass}" >
<View
android:id="@+id/horizontalStrut"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerVertical="true" />
<View
android:id="@+id/verticalStrut"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/horizontalStrut"
android:layout_toLeftOf="@id/verticalStrut"
android:background="@color/red" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/horizontalStrut"
android:layout_toRightOf="@id/verticalStrut"
android:background="@color/black" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/horizontalStrut"
android:layout_toLeftOf="@id/verticalStrut"
android:background="@color/blue" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/horizontalStrut"
android:layout_toRightOf="@id/verticalStrut"
android:background="@color/green" >
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
226 次 |
| 最近记录: |