Relativelayout中的Scrollview在android中无法正常滚动
在我的屏幕设计中,我有一个动作栏和底部栏,基本上是一个线性布局。在屏幕中间,我有几个文本视图和4-5个按钮。我想在屏幕的中间部分添加滚动条。但它不起作用 我的代码在这里:Relativelayout中的Scrollview在android中无法正常滚动,android,scrollview,android-relativelayout,Android,Scrollview,Android Relativelayout,在我的屏幕设计中,我有一个动作栏和底部栏,基本上是一个线性布局。在屏幕中间,我有几个文本视图和4-5个按钮。我想在屏幕的中间部分添加滚动条。但它不起作用 我的代码在这里: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/toAddrdrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/fromAddrDrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/toAddrdrop"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/distanceToCoverDrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/fromAddrDrop"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/distanceToCoverDrop"
android:orientation="vertical">
<Button
android:id="@+id/drop_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Drop Confirm" />
<Button
android:id="@+id/sai_out_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Sai Out" />
<Button
android:id="@+id/customer_in_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Customer In" />
<Button
android:id="@+id/customer_out_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Customer Out" />
<Button
android:id="@+id/customer_new_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Customer new" />
<Button
android:id="@+id/customer_new_drop22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Customer new 22" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/buttombardrop"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:background="#33B5E5"
android:orientation="horizontal">
<Button
android:id="@+id/callButton_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@android:drawable/ic_menu_call"
android:paddingTop="8dp"
android:text="Call"
android:textColor="#FFFFFF" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#ffffff" />
<Button
android:id="@+id/mapButton_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@android:drawable/ic_menu_mapmode"
android:paddingTop="8dp"
android:text="Map"
android:textColor="#FFFFFF" />
</LinearLayout >
</RelativeLayout>
我观察到,我能够滚动一点直到4个按钮。如何修复scrollview。
请帮忙 你应该注意,RelativeLayout的行为常常出乎意料。所以你应该使用线性布局
只需将代码替换为
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/toAddrdrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/fromAddrDrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/toAddrdrop"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/distanceToCoverDrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/fromAddrDrop"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/distanceToCoverDrop"
android:orientation="vertical">
<Button
android:id="@+id/drop_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Drop Confirm" />
<Button
android:id="@+id/sai_out_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Sai Out" />
<Button
android:id="@+id/customer_in_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Customer In" />
<Button
android:id="@+id/customer_out_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Customer Out" />
<Button
android:id="@+id/customer_new_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Customer new" />
<Button
android:id="@+id/customer_new_drop22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/button_active"
android:text="Customer new 22" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/buttombardrop"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="#33B5E5"
android:orientation="horizontal">
<Button
android:id="@+id/callButton_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@android:drawable/ic_menu_call"
android:paddingTop="8dp"
android:text="Call"
android:textColor="#FFFFFF" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#ffffff" />
<Button
android:id="@+id/mapButton_drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@android:drawable/ic_menu_mapmode"
android:paddingTop="8dp"
android:text="Map"
android:textColor="#FFFFFF" />
</LinearLayout >
</LinearLayout>
你应该把ScrollView作为一切事物的父对象,把你的android:xlmns放在它里面,还有任何其他的上下文,比如.MainActivity。你让我开心。我所做的唯一更改是,我为底部栏线性布局添加了android:layou\u gravity=bottom。剩下的代码是你的..你不需要布局重力底部,因为我在scrollviewLinear布局权重中添加了权重1,这比你想象的要多得多。我还注意到你在底部视图中添加了-android:layout\u height=0dp。你为什么这么做?