【问题标题】:View should scroll if screen is too small如果屏幕太小,视图应该滚动
【发布时间】:2014-02-07 16:03:51
【问题描述】:

我使用 5 英寸智能手机测试了以下视图。现在我用 HTC Wildfire 进行了测试,发现问题是,我只看到前两个按钮,而第三个按钮非常小。 如果没有足够的空间来显示按钮,我希望用户可以滚动查看完整的按钮。我做错了什么?

<RelativeLayout 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:background="@drawable/bg_ohne"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".NachdemSpiel" >

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:textStyle="bold"
    android:text="Herzlichen Glückwunsch! Dein Highscore beträgt: " />

<TextView
    android:id="@+id/tvPunkteNach"
    android:textStyle="bold"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:text="" />


    <Button
    android:id="@+id/nbtSenden"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/nbtNochmal"
    android:layout_below="@+id/tvPunkteNach"
    android:layout_marginTop="50dp"
    android:background="@drawable/highscoresenden" />


   <Button
    android:id="@+id/nbtNochmal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/nbtHauptmenu"
    android:layout_below="@+id/nbtSenden"
    android:layout_marginTop="10dp"
    android:background="@drawable/nochmalspielen" />



<Button
    android:id="@+id/nbtHauptmenu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/nbtNochmal"
    android:layout_marginTop="10dp"
    android:background="@drawable/hauptmenue" />




</RelativeLayout>

【问题讨论】:

    标签: android layout view scroll


    【解决方案1】:

    像这样将布局包装在 ScrollView 中:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_ohne">
    
    <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".NachdemSpiel" >
    
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:textStyle="bold"
        android:text="Herzlichen Glückwunsch! Dein Highscore beträgt: " />
    
    <TextView
        android:id="@+id/tvPunkteNach"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:text="" />
    
    
    <Button
        android:id="@+id/nbtSenden"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/nbtNochmal"
        android:layout_below="@+id/tvPunkteNach"
        android:layout_marginTop="50dp"
        android:background="@drawable/highscoresenden" />
    
    
    <Button
        android:id="@+id/nbtNochmal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/nbtHauptmenu"
        android:layout_below="@+id/nbtSenden"
        android:layout_marginTop="10dp"
        android:background="@drawable/nochmalspielen" />
    
    <Button
        android:id="@+id/nbtHauptmenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/nbtNochmal"
        android:layout_marginTop="10dp"
        android:background="@drawable/hauptmenue" />
    
    </RelativeLayout>
    </ScrollView>
    

    【讨论】:

      【解决方案2】:

      为此,您必须使用ScrollView。 ScrollView 只能有一个孩子,所以你必须包裹整个RelativeLayout

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多