【发布时间】:2016-10-07 11:25:17
【问题描述】:
是否可以动态创建宽度为 50% 的布局,因此第三个布局低于第一个布局?我试过android:layout_weight=".5",但它不起作用。
编辑:目前还没有正确的答案
【问题讨论】:
-
"so 3rd one to be on the bottom of first first" 是什么意思?
-
第一个下
是否可以动态创建宽度为 50% 的布局,因此第三个布局低于第一个布局?我试过android:layout_weight=".5",但它不起作用。
编辑:目前还没有正确的答案
【问题讨论】:
您可以使用 LinearLayout 进行以下操作:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:gravity="left"
android:orientation="horizontal">
<TextView
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Takes up half the width" />
</LinearLayout>
通过在父项上设置 weightSum,您是说子项的权重应该等于该数量。通过将独生子女的体重设置为一半,它将占用一半的空间。确保将子项的宽度设置为 0,以便它知道使用权重值来计算其相对于其父项的空间。
【讨论】:
你可以使用Percent Support Library:
添加库
编译'com.android.support:percent:23.3.0'
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentFrameLayout>
【讨论】: