android中多线性布局视图的滚动条
我在android应用程序中有一个弹出视图。对于纵向屏幕,弹出页面正确显示,但如果我旋转屏幕以部分横向显示弹出布局。我在弹出窗口中有单击按钮。无法在横向模式下查看按钮。我使用的弹出页面是android中多线性布局视图的滚动条,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我在android应用程序中有一个弹出视图。对于纵向屏幕,弹出页面正确显示,但如果我旋转屏幕以部分横向显示弹出布局。我在弹出窗口中有单击按钮。无法在横向模式下查看按钮。我使用的弹出页面是 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.and
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/popup_element"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#333333"
android:gravity="center"
android:orientation="vertical"
tools:ignore="ButtonStyle" >
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose_emotion"
android:textColor="@color/white"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_sad"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/sky_ring"
android:text="@string/emo_sad"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_happy"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/yellow_ring"
android:text="@string/emo_happy"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_depressed"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/blue_ring"
android:text="@string/emo_depressed"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_question"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_margin="8dp"
android:background="@drawable/gray_ring_question"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_anxious"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/orange_ring"
android:text="@string/emo_anxious"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_neutral"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/white_ring"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:text="@string/emo_neutral"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_angry"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/red_ring"
android:text="@string/emo_angry"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_done_popup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:text="@string/done_btn"
android:textColor="@color/white" />
<Button
android:id="@+id/btn_close_popup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:text="@string/cancel_btn"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
如何在横向屏幕或小屏幕上显示整个页面?任何帮助都将不胜感激。提前感谢。您不能在scrollview中设置多个LinearLayout,但如果您想这样做,请将所有LinearLayout放在一个LinearLayout中,然后将其放在scrollview中 使用滚动视图包装线性布局 请看这里
滚动视图是一个框架布局,意思是您必须在其中放置一个子视图,其中包含要滚动的全部内容;此子对象本身可能是具有复杂对象层次结构的布局管理器 因此,你必须尽可能通过概念清理来解决你的问题。愿它能澄清你的想法,帮助你解决问题 在scrollview中只能使用单个标记(子布局)。如果您已经放置了多个线性布局,那么请使用单线性布局,然后在此中放置其他线性布局。检查此项我使用了您的xml(更改您的背景):-
试试这个,因为您知道ScrollView只能有一个子元素,所以您将ScrollView作为父布局,然后一个子元素将成为linearlayout,然后就可以工作了。试着这样做:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/popup_element"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#333333"
android:gravity="center"
android:orientation="vertical"
tools:ignore="ButtonStyle" >
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose_emotion"
android:textColor="@color/white"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_sad"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/sky_ring"
android:text="@string/emo_sad"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_happy"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/yellow_ring"
android:text="@string/emo_happy"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_depressed"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/blue_ring"
android:text="@string/emo_depressed"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_question"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_margin="8dp"
android:background="@drawable/gray_ring_question"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_anxious"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/orange_ring"
android:text="@string/emo_anxious"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_neutral"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/white_ring"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:text="@string/emo_neutral"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_angry"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/red_ring"
android:text="@string/emo_angry"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_done_popup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:text="@string/done_btn"
android:textColor="@color/white" />
<Button
android:id="@+id/btn_close_popup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:text="@string/cancel_btn"
android:textColor="@color/white" />
</LinearLayout>
但最好使用RelativeLayout,而不是使用如此多的线性布局。希望有帮助。它抛出了一个警告:“ScrollView只能承载一个直接子对象”。正如你在我的视图中所看到的,我有不止一个线性布局。是的,你不能在scrollview中设置多个线性布局…如果你想检查我的答案,请将你所有的线性布局放在这里面,你必须在scroll视图下面设置一个父布局。这就是我说的,将你所有的线性布局放在父线性布局并使用滚动视图将其包裹
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/popup_element"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#333333"
android:gravity="center"
android:orientation="vertical"
tools:ignore="ButtonStyle" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="choose_emotion"
android:textColor="@color/white"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_sad"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/ic_launcher"
android:text="emo_sad"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_happy"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/ic_launcher"
android:text="emo_happy"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_depressed"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/ic_launcher"
android:text="emo_depressed"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_question"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_margin="8dp"
android:background="@drawable/ic_launcher"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_anxious"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/ic_launcher"
android:text="emo_anxious"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_neutral"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/ic_launcher"
android:text="emo_neutral"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_angry"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/ic_launcher"
android:text="emo_angry"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_done_popup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:text="done_btn"
android:textColor="@color/white" />
<Button
android:id="@+id/btn_close_popup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:text="cancel_btn"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/popup_element"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#333333"
android:gravity="center"
android:orientation="vertical"
tools:ignore="ButtonStyle" >
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose_emotion"
android:textColor="@color/white"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_sad"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/sky_ring"
android:text="@string/emo_sad"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_happy"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/yellow_ring"
android:text="@string/emo_happy"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_depressed"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/blue_ring"
android:text="@string/emo_depressed"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_question"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_margin="8dp"
android:background="@drawable/gray_ring_question"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_anxious"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/orange_ring"
android:text="@string/emo_anxious"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/emo_neutral"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/white_ring"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:text="@string/emo_neutral"
android:textColor="@color/white"
android:textSize="12sp" />
<Button
android:id="@+id/emo_angry"
android:layout_width="83dp"
android:layout_height="83dp"
android:background="@drawable/red_ring"
android:text="@string/emo_angry"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_done_popup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:text="@string/done_btn"
android:textColor="@color/white" />
<Button
android:id="@+id/btn_close_popup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:text="@string/cancel_btn"
android:textColor="@color/white" />
</LinearLayout>