你能做的就是约束你的
FrameLayout
从右到左
search_layout
所以它们不会重叠。最后一条路
Button
将完全可见。
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/horizontal_scroll_container"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/search_layout">
这个
width
已更改为
0dp
(
MATCH_CONSTRAINT
)所以
ScrollView
获取所有可用的水平空间。
事实上,
框架布局
根本不需要容器。
HorizontallScrollView
是
框架布局
所以没必要把它们窝起来。同样的结果也可以通过
HorizontalScrollView
作为
ConstraintLayout
以下内容:
<?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"
android:maxHeight="50dp"
tools:context=".navigation.NavigationFragment">
<HorizontalScrollView
android:id="@+id/horizontal_scroll"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/search_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5"
style="?android:attr/borderlessButtonStyle"/>
</LinearLayout>
</HorizontalScrollView>
<FrameLayout
android:id="@+id/search_layout"
android:layout_width="58dp"
android:layout_height="match_parent"
android:background="@color/colorAccent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@id/horizontal_scroll"/>
</android.support.constraint.ConstraintLayout>