想要在android中的滚动视图中使用全屏按钮吗

想要在android中的滚动视图中使用全屏按钮吗,android,android-layout,scrollview,android-layout-weight,Android,Android Layout,Scrollview,Android Layout Weight,我想在活动中放置9个按钮,但有两个条件: 1.如果屏幕很小,按钮会滚动 2.如果屏幕足够大,一次就可以容纳所有人,那么他们就会被拉伸以填满屏幕 我试过了,但没用。谢谢 您必须在res文件夹中创建名为layout small、layout large的文件夹,为它们制作不同的布局,如下所述: 当然,将使用名为“layout”的文件夹。但是,当您创建一个名为layout small的文件夹时,如果屏幕大小低于470dp x 320dp(这是layout normal的最低分辨率),则将使用该

我想在活动中放置9个按钮,但有两个条件:

1.如果屏幕很小,按钮会滚动

2.如果屏幕足够大,一次就可以容纳所有人,那么他们就会被拉伸以填满屏幕

我试过了,但没用。谢谢



您必须在res文件夹中创建名为layout small、layout large的文件夹,为它们制作不同的布局,如下所述:

当然,将使用名为“layout”的文件夹。但是,当您创建一个名为layout small的文件夹时,如果屏幕大小低于470dp x 320dp(这是layout normal的最低分辨率),则将使用该文件夹

对于拉伸,在线性布局中使用布局权重和权重和,以使布局看起来适合预览

删除权重参数,并将布局高度设置为包裹内容,如下所示:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#fff0fd"
            android:orientation="vertical"
            android:layout_margin="8dp">

        <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/First_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Second_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="onButtonClick"
                android:singleLine="true"
                android:text="@string/Third_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Forth_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Fifth_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Sixth_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Seventh_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button8"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Eighth_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Gate"
                android:textStyle="bold"/>

    </LinearLayout>
</ScrollView>

您可以在编辑器中预览不同的屏幕分辨率,以确定使用或不使用scrollview时的屏幕分辨率:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#fff0fd"
            android:orientation="vertical"
            android:layout_margin="8dp">

        <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/First_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Second_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="onButtonClick"
                android:singleLine="true"
                android:text="@string/Third_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Forth_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Fifth_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Sixth_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Seventh_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button8"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Eighth_Semester"
                android:textStyle="bold"/>

        <Button
                android:id="@+id/button9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="@string/Gate"
                android:textStyle="bold"/>

    </LinearLayout>
</ScrollView>