【问题标题】:Android Scroll View space in the bottomAndroid Scroll View 底部空间
【发布时间】:2017-10-13 18:08:36
【问题描述】:

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

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

和屏幕:

【问题讨论】:

  • 为什么要给线性布局布局高度和宽度?
  • 这个 android studio 把自动...
  • 如果有用别忘了采纳我的回答

标签: android xml android-scrollview


【解决方案1】:

您需要在第一个 LinearLayout 的高度和宽度参数中更改为“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">

    ...

希望对你有帮助,

【讨论】:

    【解决方案2】:

    你应该改变:

    <?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="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="1">
    

    【讨论】:

      【解决方案3】:

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

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

      并移除子线性布局。

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

      【讨论】:

        猜你喜欢
        • 2018-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-11
        • 1970-01-01
        • 1970-01-01
        • 2011-12-11
        • 2020-02-16
        相关资源
        最近更新 更多