【问题标题】:Why isn't the whole screen used?为什么不使用整个屏幕?
【发布时间】:2017-03-12 05:00:12
【问题描述】:

当我在手机上执行此代码时,它只填满了一半的屏幕。即使我添加了更多视图,所有的变化都是我现在可以滚动,但总体上屏幕并没有被更多地使用。所以我的猜测是,我在滚动视图上犯了一个错误,但是在哪里呢?很高兴听到有关如何使布局使用整个屏幕的任何建议。提前谢谢!

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_mahlzeiten"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="3">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:layout_weight="3">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:text="produkt"
                    android:layout_weight="1"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:text="produkt"
                    android:layout_weight="1"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:text="produkt"
                    android:layout_weight="1"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:text="produkt"
                    android:layout_weight="1"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:text="produkt"
                    android:layout_weight="1"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:text="produkt"
                    android:layout_weight="1"/>



            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="-" />

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="+" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="-" />

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="+" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="-" />

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="+" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="-" />

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="+" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="-" />

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="+" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="-" />

                    <Button
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:text="+" />

                </LinearLayout>
            </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_weight="1"
                >

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Speisen hinzufügen"/>


            </LinearLayout>





    </LinearLayout>
</ScrollView>

【问题讨论】:

    标签: android xml layout view


    【解决方案1】:

    您需要将所有布局整合到一个通用布局中。这样的东西对你很有用:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/activity_mahlzeiten"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="3">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3"
            android:orientation="horizontal">
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
    
                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:orientation="vertical">
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1"
                            android:text="produkt" />
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1"
                            android:text="produkt" />
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1"
                            android:text="produkt" />
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1"
                            android:text="produkt" />
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1"
                            android:text="produkt" />
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1"
                            android:text="produkt" />
    
    
                    </LinearLayout>
    
                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical">
    
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1">
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="-" />
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="+" />
    
                        </LinearLayout>
    
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1">
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="-" />
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="+" />
    
                        </LinearLayout>
    
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1">
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="-" />
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="+" />
    
                        </LinearLayout>
    
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1">
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="-" />
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="+" />
    
                        </LinearLayout>
    
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1">
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="-" />
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="+" />
    
                        </LinearLayout>
    
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1">
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="-" />
    
                            <Button
                                android:layout_width="48dp"
                                android:layout_height="48dp"
                                android:text="+" />
    
                        </LinearLayout>
    
                    </LinearLayout>
    
                </LinearLayout>
            </ScrollView>
    
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal">
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Speisen hinzufügen" />
    
        </LinearLayout>
    
    </LinearLayout>
    

    如您所见,按钮位于底部,当您再添加一些项目时,ScrollView 将起作用。

    祝你有美好的一天!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多