【发布时间】:2019-03-29 05:41:06
【问题描述】:
我正在尝试创建从按钮底部开始的列表布局,它是屏幕宽度的 3/4。
就像这样:
首先,我使用了水平和垂直的嵌套线性布局,但后来我读到 here 说约束布局的响应速度更快,我印象深刻并试了一下。
所以,我尝试将外部布局替换为约束布局,但现在,我无法将列表限制为从按钮的 底部 开始,而是从屏幕顶部开始。 我试图看看如果我用一个按钮替换整个线性布局会发生什么,只是为了看看属性是否正确实现并且它工作,所以我明白约束布局不会影响线性布局的儿子,尽管它应该影响整个布局(如我所见)。
我的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFFFFF"
android:src="@drawable/ic_menu_black_32dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="@+id/list_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/settings_button"
app:layout_constraintTop_toBottomOf="@+id/settings_button">
<ListView
android:id="@+id/listview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
我当前的布局如下所示:
我真的很感谢帮助者!
【问题讨论】:
-
您好,您能否将屏幕截图添加到您的布局中?
-
已添加! @Traabefi
标签: android android-linearlayout android-constraintlayout