这是我的代码
我需要让它看起来没有Scrollview没有堆叠 我无法将我的LinearLayout xmlns:android设置为Scroll视图,因为我不希望我的工具栏开始四处移动。
<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 ScrollView) [2]:http://i.stack.imgur.com/YBcRz.png(With ScrollView)
答案 0 :(得分:0)
只需将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>