android - ScrollView 填满整个屏幕

标签 android android-layout

我的 View 包含一个内部有多个 View 的 ScrolView,以及另一个 ID 为“bottom_view”的 LinearLayout。 问题是,如果 ScrolView 包含很多 View ,它会隐藏“bottom_view”LinearLayout。

这是我的代码:

<?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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    tools:context=".MainActivity">

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

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="10dp"
            android:background="@drawable/customborder"

            tools:context=".MainActivity">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/dialog_text_layout_name"
                >
                <TextView
                    android:id="@+id/dialog_text_product_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:textSize="20sp"
                    android:visibility="visible"
                    android:adjustViewBounds="true"
                    android:text="name" />
            </LinearLayout>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/dialog_text_layout_name"

                >

                <com.parse.ParseImageView
                    android:id="@+id/img_row_logo"
                    android:layout_width="wrap_content"
                    android:layout_height="200sp"
                    android:layout_gravity="center"

                    android:src="@drawable/no_image"
                    android:adjustViewBounds="true"
                    android:visibility="visible">
                </com.parse.ParseImageView>

                <TextView
                    android:id="@+id/price"
                    android:layout_gravity="left|center_vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="24sp"
                    android:textSize="20sp"
                    android:text="מחיר"
                    android:textColor="#ffffff"
                    android:background="#FF8000"

                    >
                </TextView>
            </FrameLayout>
            <TextView
                android:id="@+id/dialog_text_product_desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="50dp"
                android:gravity="start"
                android:visibility="gone"
                android:textSize="20sp"
                android:text="אין תיאור"
                />
            <TextView
                android:id="@+id/dialog_text_business_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:text="מחסני חשמל"
                android:textColor="#FF8000"
                android:textSize="20sp"/>


            <TextView
                android:id="@+id/dialog_address"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="יפו 30 ירושלים"
                android:layout_gravity="end"
                android:layout_marginTop="20sp"
                android:textSize="20sp"/>

            <LinearLayout
                android:gravity="right"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:layout_marginTop="15sp"
                android:orientation = "horizontal" >
                <TextView
                    android:id="@+id/dialog_telephone_text"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="03-1234567"
                    android:textSize="20sp"/>
                <TextView
                    android:id="@+id/dialog_telephone"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="20sp"
                    android:text="טלפון: "/>

            </LinearLayout>

            <LinearLayout
                android:gravity="right"
                android:layout_width="match_parent"
                android:layout_height="45sp"
                android:orientation = "horizontal" >
                <TextView
                    android:id="@+id/dialog_text_distance"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="מרחק לא ידוע"
                    android:textSize="20sp"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation = "vertical" >
                <TextView
                    android:id="@+id/dialog_open_hours"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true"
                    android:layout_gravity="end"
                    android:text="שעות פתיחה"
                    android:textSize="20sp"/>
                <TextView
                    android:id="@+id/dialog_open_hours_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="אין מידע"
                    android:textSize="20sp"/>

            </LinearLayout>
        </LinearLayout>
    </ScrollView>

    <LinearLayout
    android:id="@+id/bottom_view"
    android:background="@drawable/my_black"
    android:layout_width="match_parent"
    android:layout_height="25dp"
    android:orientation = "horizontal"
    android:layout_alignParentBottom="true">

    <ImageView
        android:layout_gravity="left"
        android:id="@+id/phone"
        android:layout_width="0dp"
        android:layout_weight= "1"
        android:layout_height="match_parent"
        android:src="@drawable/phone"
        android:visibility="visible">
    </ImageView>

    <ImageView
        android:id="@+id/share"
        android:layout_width="0dp"
        android:layout_weight= "1"
        android:layout_height="match_parent"
        android:src="@drawable/share_btn"
        android:visibility="visible">
    </ImageView>

    <ImageView
        android:id="@+id/images"
        android:layout_width="0dp"
        android:layout_weight= "1"
        android:layout_height="match_parent"
        android:src="@drawable/images"
        android:visibility="visible">
    </ImageView>

    <ImageView
        android:id="@+id/home"
        android:layout_width="0dp"
        android:layout_weight= "1"
        android:layout_height="match_parent"
        android:src="@drawable/home_con_white"
        android:visibility="visible">
    </ImageView>

    </LinearLayout>
</LinearLayout>

谢谢!

最佳答案

ScrollView 布局高度更改为:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

问题是 ScrollView 内的 LinearLayoutmatch_parent 高度,它强制 ScrollView 采取整个屏幕。

关于android - ScrollView 填满整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28131582/

相关文章:

android - 使用 Android NDK 发现蓝牙

android - ProgressDialog.show() 的上下文参数是什么?

java - 在android中等待并通知

android BottomAppBar 有额外的左侧填充

android - 尝试在我的应用程序中创建塞子

android - 如何修复 onSaveInstanceState 中的 java.lang.IllegalStateException

android - 如何在 android 操作栏中放置标签/文本,如显示钱包余额等

android - 在android中布局一侧曲线形状

android - 如何在约束布局中将单个边框放在多个元素周围?

android - 如何使每个可滚动布局都适合屏幕宽度?