【发布时间】:2016-04-07 16:14:49
【问题描述】:
嗨,我现在有点难过。我认为这在 Android XML 中是可能的。
我想做这样的布局:
问题在于并排的两个小元素。当我使 view#2 与高度匹配时,我希望它也会尊重其他兄弟的空间。我错了,但我现在明白了。当我将 view#2 的 layout_height 设置为 match_parent 时,它会占用剩余空间,并且 view#3 和 view#4 被放入最底部并且不再在屏幕中可见。
我希望 view#2 会在中间扩展,但仍然为 view#3 和 view#4 以及它下面的一些元素腾出一些空间,而不是被推到下面。
这是我现在正在做的事情:
<RelativeLayout
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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:fitsSystemWindows="true"
tools:context=".TaskActivity">
<android.support.design.widget.TextInputLayout
android:id="@+id/textinput_layout_note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp">
<EditText
android:id="@+id/edittext_task"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="true"
android:textSize="32sp"
android:padding="8dp"
android:hint="@string/edittext_task_title_hint"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textinput_layout_note_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textinput_layout_note_title">
<EditText
android:id="@+id/edittext_todo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="1"
android:gravity="top"
android:hint="@string/edittext_task_content_hint"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textinput_layout_note_description"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imagebutton_insert_note"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_content_add_black"
android:contentDescription="@string/content_description_choose_note"
style="?android:attr/borderlessButtonStyle" />
<ImageButton
android:id="@+id/imagebutton_expand_note"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_open_in_new_black_24dp"
android:contentDescription="@string/content_description_expand_note"
style="?android:attr/borderlessButtonStyle" />
</LinearLayout>
</RelativeLayout>
我已经将 LinearLayout 与 layout_weight 结合使用,但这会变得越来越慢,因为我有一些也需要权重的嵌套视图。我希望这是相对完成的。
有什么想法可以实现这种布局吗?
谢谢!
【问题讨论】: