我需要 android 布局配置
I need android layout configurations
70% 30% 布局是用LinearLayout的weightsum做的。但是,图像布局不能叠加在它上面。我做错方法了吗?
您可以使用 ContraintLayout 以获得更大的灵活性。
使用app:layout_constraintHeight_percent
属性以百分比表示高度
您可以使用以下代码在两个布局之间对齐 Image
。
app:layout_constraintBottom_toTopOf="@id/layout2"
app:layout_constraintTop_toBottomOf="@id/layout1"
这是实现您提到的布局的完整代码。
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@id/layout2"
app:layout_constraintHeight_percent="0.7" // 70% of height
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent="0.3" // 30% of height
app:layout_constraintTop_toBottomOf="@id/layout1">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center" />
</LinearLayout>
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
// To align image between layout1 and layout2
app:layout_constraintBottom_toTopOf="@id/layout2"
app:layout_constraintTop_toBottomOf="@id/layout1" />
</android.support.constraint.ConstraintLayout>
70% 30% 布局是用LinearLayout的weightsum做的。但是,图像布局不能叠加在它上面。我做错方法了吗?
您可以使用 ContraintLayout 以获得更大的灵活性。
使用app:layout_constraintHeight_percent
属性以百分比表示高度
您可以使用以下代码在两个布局之间对齐 Image
。
app:layout_constraintBottom_toTopOf="@id/layout2"
app:layout_constraintTop_toBottomOf="@id/layout1"
这是实现您提到的布局的完整代码。
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@id/layout2"
app:layout_constraintHeight_percent="0.7" // 70% of height
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent="0.3" // 30% of height
app:layout_constraintTop_toBottomOf="@id/layout1">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center" />
</LinearLayout>
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
// To align image between layout1 and layout2
app:layout_constraintBottom_toTopOf="@id/layout2"
app:layout_constraintTop_toBottomOf="@id/layout1" />
</android.support.constraint.ConstraintLayout>