ScrollView 实现超过 1 个相关布局
ScrollView implementing more than 1 relativelayout
这是我的代码
我需要让它看起来像没有滚动视图不堆叠
我无法将我的 LinearLayout xmlns:android 设置为滚动视图,因为我不想让我的工具栏开始四处移动。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1"
tools:context=".HistoryScreen">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="370dp"
android:layout_height="64dp"
android:background="@color/ColorPrimary"
android:minHeight="?attr/actionBarSize"
android:scrollbars="none">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_history"
android:textColor="@color/TitleColor"
android:textSize="22sp" />
</android.support.v7.widget.Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:text="@string/History3" />
<ImageButton
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show"
android:background="#000" />
<ImageButton
android:id="@+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description_text1"
android:maxLines="5"
android:text="@string/History2" />
<ImageButton
android:id="@+id/show1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text1"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text1"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show1"
android:background="#000" />
<ImageButton
android:id="@+id/hide1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text1"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description_text2"
android:maxLines="5"
android:text="@string/history4">
</TextView>
<ImageButton
android:id="@+id/show2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text2"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text2"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show2"
android:background="#000" />
<ImageButton
android:id="@+id/hide2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text2"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>'
[1]: http://i.stack.imgur.com/bHtXq.png(Without 滚动视图)
[2]: http://i.stack.imgur.com/YBcRz.png(With滚动视图)
只需将 ScrollView 中的 RelativeLayout
更改为 LinearLayout
和 android:orientation="vertical"
即可。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1"
tools:context=".HistoryScreen">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="370dp"
android:layout_height="64dp"
android:background="@color/ColorPrimary"
android:minHeight="?attr/actionBarSize"
android:scrollbars="none">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_history"
android:textColor="@color/TitleColor"
android:textSize="22sp" />
</android.support.v7.widget.Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:text="@string/History3" />
<ImageButton
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show"
android:background="#000" />
<ImageButton
android:id="@+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description_text1"
android:maxLines="5"
android:text="@string/History2" />
<ImageButton
android:id="@+id/show1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text1"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text1"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show1"
android:background="#000" />
<ImageButton
android:id="@+id/hide1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text1"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description_text2"
android:maxLines="5"
android:text="@string/history4">
</TextView>
<ImageButton
android:id="@+id/show2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text2"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text2"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show2"
android:background="#000" />
<ImageButton
android:id="@+id/hide2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text2"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
这是我的代码
我需要让它看起来像没有滚动视图不堆叠 我无法将我的 LinearLayout xmlns:android 设置为滚动视图,因为我不想让我的工具栏开始四处移动。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1"
tools:context=".HistoryScreen">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="370dp"
android:layout_height="64dp"
android:background="@color/ColorPrimary"
android:minHeight="?attr/actionBarSize"
android:scrollbars="none">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_history"
android:textColor="@color/TitleColor"
android:textSize="22sp" />
</android.support.v7.widget.Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:text="@string/History3" />
<ImageButton
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show"
android:background="#000" />
<ImageButton
android:id="@+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description_text1"
android:maxLines="5"
android:text="@string/History2" />
<ImageButton
android:id="@+id/show1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text1"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text1"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show1"
android:background="#000" />
<ImageButton
android:id="@+id/hide1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text1"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description_text2"
android:maxLines="5"
android:text="@string/history4">
</TextView>
<ImageButton
android:id="@+id/show2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text2"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text2"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show2"
android:background="#000" />
<ImageButton
android:id="@+id/hide2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text2"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>'
[1]: http://i.stack.imgur.com/bHtXq.png(Without 滚动视图) [2]: http://i.stack.imgur.com/YBcRz.png(With滚动视图)
只需将 ScrollView 中的 RelativeLayout
更改为 LinearLayout
和 android:orientation="vertical"
即可。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1"
tools:context=".HistoryScreen">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="370dp"
android:layout_height="64dp"
android:background="@color/ColorPrimary"
android:minHeight="?attr/actionBarSize"
android:scrollbars="none">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_history"
android:textColor="@color/TitleColor"
android:textSize="22sp" />
</android.support.v7.widget.Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:text="@string/History3" />
<ImageButton
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show"
android:background="#000" />
<ImageButton
android:id="@+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description_text1"
android:maxLines="5"
android:text="@string/History2" />
<ImageButton
android:id="@+id/show1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text1"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text1"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show1"
android:background="#000" />
<ImageButton
android:id="@+id/hide1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text1"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/description_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description_text2"
android:maxLines="5"
android:text="@string/history4">
</TextView>
<ImageButton
android:id="@+id/show2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text2"
android:background="@drawable/arrow_down"
android:clickable="true" />
<View
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="@+id/description_text2"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/show2"
android:background="#000" />
<ImageButton
android:id="@+id/hide2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/description_text2"
android:background="@drawable/arrow_up"
android:clickable="true"
android:visibility="invisible" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>