Android在底部滚动查看空间

Android在底部滚动查看空间,android,xml,android-scrollview,Android,Xml,Android Scrollview,我想要一个设计屏幕的帮助。。我想制作一个带有图片和文本(滚动条)的详细屏幕。。但是当我测试时,文本并没有填满所有的空间…它在文本的底部放了一个空白。。。如何用文本填充所有布局 <?xml version="1.0" encoding="utf-8"?> <android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schema

我想要一个设计屏幕的帮助。。我想制作一个带有图片和文本(滚动条)的详细屏幕。。但是当我测试时,文本并没有填满所有的空间…它在文本的底部放了一个空白。。。如何用文本填充所有布局

<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rs.app.paginas.antena_detalhe">

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="495dp"
        android:orientation="vertical"
        android:weightSum="1"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_weight="0.05"
            android:gravity="center_vertical|center_horizontal"
            android:orientation="horizontal"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="0dp">

            <ImageView
                android:id="@+id/imgAntena"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                app:srcCompat="@mipmap/baloon" />

        </LinearLayout>

        <TextView
            android:id="@+id/txtTitulo"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:text="Nome" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:adjustViewBounds="true"
            android:fillViewport="true"
            >

            <TextView
                android:id="@+id/txtDetalhes"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:scrollbars="vertical" />
        </ScrollView>

    </LinearLayout>

</android.widget.RelativeLayout>


您应该更改为:

<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rs.app.paginas.antena_detalhe">
    <LinearLayout
            android:layout_width="368dp"
            android:layout_height="495dp"
            android:orientation="vertical"
            android:weightSum="1"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="8dp">

致:


您应该更改为:

<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rs.app.paginas.antena_detalhe">
    <LinearLayout
            android:layout_width="368dp"
            android:layout_height="495dp"
            android:orientation="vertical"
            android:weightSum="1"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="8dp">

致:


在布局中,您为包含滚动视图和其他小部件的线性布局定义了固定尺寸。我建议将根布局更改为最大宽度和高度的线性布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp"
tools:context="com.example.rs.app.paginas.antena_detalhe">

并删除子线性布局


您获得额外空间的原因是因为固定高度,这可能在高度较低的手机上不存在。

在布局中,您为包含滚动视图和其他小部件的线性布局定义了固定尺寸。我建议将根布局更改为最大宽度和高度的线性布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp"
tools:context="com.example.rs.app.paginas.antena_detalhe">

并删除子线性布局

您获得额外空间的原因是因为固定高度,而固定高度可能不会出现在高度较低的手机上。

您需要在第一行布局的高度和宽度参数中更改为“匹配父项”,以填充所有屏幕,因为在这种情况下,父项是您手机的屏幕,但是如果你按照代码(495dp)所示在dp中定义值,那么它只会填充这些尺寸,屏幕尺寸会随着每部手机和他自己的屏幕大小而变化,这就是为什么它在一些小屏幕设备中工作,而在大屏幕设备中可能无法工作的原因,使其适用于各种屏幕大小的最佳解决方案是如下更改代码:

<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rs.app.paginas.antena_detalhe">

    <LinearLayout
        android:layout_width="match_parent"           
        android:layout_height="match_parent"          
        android:orientation="vertical"
        android:weightSum="1"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

    ...

...
希望有帮助,

您需要在第一个线性布局的高度和宽度参数中更改为“匹配父项”以填充所有屏幕,因为在这种情况下,父项是您手机的屏幕,但如果您在代码(495dp)中定义dp值,则只会填充该尺寸,屏幕尺寸会随着每部手机和他自己的屏幕尺寸而变化,这就是为什么它在一些小屏幕设备中工作,而大屏幕可能无法做到这一点,让它在每种屏幕尺寸下工作的最佳解决方案是如下更改代码:

<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rs.app.paginas.antena_detalhe">

    <LinearLayout
        android:layout_width="match_parent"           
        android:layout_height="match_parent"          
        android:orientation="vertical"
        android:weightSum="1"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

    ...

...

希望能有所帮助,

为什么要将版面高度和宽度设置为线性版面?这是android studio的自动设置…如果有用,请不要忘记接受我的答案为什么要将版面高度和宽度设置为线性版面?这是android studio的自动设置…如果有用,请不要忘记接受我的答案