简体   繁体   English

底部的Android Scroll View空间

[英]Android Scroll View space in the bottom

I want a help for design a screen.. I want to make a details screen, with a picture and a text (scrollabe).. But when i test, the text doesnt fill all the space...Its puts a empty space at the bottom of the text... How can i fill all the layout with the text? 我想要一个设计屏幕的帮助。我想制作一个包含图片和文本(卷轴)的详细信息屏幕。但是当我测试时,文本不会填满所有的空间……它在文本底部...如何用文本填充所有布局?

<?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>

and the screen: 和屏幕:

在此处输入图片说明

You should change from: 您应该从以下位置更改:

<?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">

to: 至:

<?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">

In your layout you have defined fixed dimensions for your linear layout which contains your scroll view and other widgets. 在布局中,您已为包含滚动视图和其他小部件的线性布局定义了固定尺寸。 I would suggest changing your root layout to Linear Layout with maximum width and height : 我建议将您的根布局更改为最大宽度和高度为线性的布局:

<?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">

And remove the child linear layout. 并删除子线性布局。

Reason you were getting extra space was because of fixed height,which may be not present on phone with lesser height. 您获得额外空间的原因是固定高度,较小高度的手机可能不存在此高度。

You need to change to "match_parent" in your first LinearLayout´s height and widht parameters to fill all the screen, cause the parent in this case is your phone' screen, but if you define values in dp as shown in your code (495dp) then it´ll fill just that dimensions, and the screen dimensions change with every phone and his own screen size, that´s why it works in some little screen devices, and with bigger screens probably wont do it, the best solution to make it work with every screen size is changing your code like this: 您需要在第一个LinearLayout的height和widht参数中将其更改为“ match_parent”才能填满整个屏幕,因为在这种情况下,父级是您手机的屏幕,但是如果您按照dp中的值定义,如代码所示(495dp ),那么它将仅填充该尺寸,并且屏幕尺寸会随每部手机和自己的屏幕尺寸而变化,这就是为什么它可以在某些小型屏幕设备中使用,而在较大的屏幕上可能无法做到这一点,这是制作此产品的最佳解决方案它适用于每种屏幕尺寸,正在更改您的代码,如下所示:

<?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">

    ...

Hope it helps, 希望能帮助到你,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM