当文本太多时,ScrollView会覆盖我的按钮

问题描述 投票:0回答:3

当我有太多文字时,我遇到了一个问题。 ScrollView扩展并覆盖底部的按钮。我已经尝试使用android:layout_below和android:layout_above来尝试解决问题,但它不起作用。

我无法在LinearLayout的底部添加边距,因为我想使按钮响应并根据屏幕分辨率更改大小。

这是我的XML代码

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:layout_weight="1"
    tools:context="app.uzzeff1.uzzef.finalapp.MainActivity">

    <LinearLayout
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:orientation="horizontal">

    </LinearLayout>

    <Button
        android:id="@+id/btnNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Next▶"
        android:layout_below="@+id/adView"
        android:layout_alignParentEnd="true"
        android:textSize="10sp"/>

    <LinearLayout
        android:id="@+id/containerlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/btnNext"
        >


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:fillViewport="true"

            >

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


                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                    android:textSize="80sp" />


            </LinearLayout>


        </ScrollView>

    </LinearLayout>


    <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/containerlayout"
        android:text="◄Back" />


</RelativeLayout>
android android-scrollview android-relativelayout
3个回答
0
投票

试试这个,将根ViewGroup更改为LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

   <RelativeLayout
      android:id="@+id/adView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

     <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:text="◄Back" />

      <Button
        android:id="@+id/btnNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:text="Next▶"
        android:textSize="10sp" />

 </RelativeLayout>


 <LinearLayout
      android:id="@+id/containerlayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:orientation="horizontal">

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

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

                <TextView
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                android:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                   android:textSize="80sp" />
  </LinearLayout>
</ScrollView>


0
投票
> Try this code solved your problem.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:orientation="horizontal"></LinearLayout>

    <Button
        android:id="@+id/btnNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/adView"
        android:text="Next▶"
        android:textSize="10sp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnNext">

        <Button
            android:id="@+id/btnBack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:text="◄Back" />

        <LinearLayout
            android:id="@+id/containerlayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

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

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


                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                        android:textSize="80sp" />
                </LinearLayout>
            </ScrollView>

        </LinearLayout>


    </RelativeLayout>

</RelativeLayout>

0
投票

尝试使用此代码。

<?xml version="1.0" encoding="utf-8"?>
<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="app.uzzeff1.uzzef.finalapp.MainActivity">

    <LinearLayout
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:orientation="horizontal">

    </LinearLayout>

    <LinearLayout
        android:id="@+id/container_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/adView"
        android:orientation="vertical">

        <Button
            android:id="@+id/btnNext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:text="Next▶"
            android:textSize="10sp" />


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

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


                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                    android:textSize="80sp" />


            </LinearLayout>
        </ScrollView>

        <Button
            android:id="@+id/btnBack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="◄Back"
            android:textSize="10sp" />
    </LinearLayout>


</RelativeLayout>

还有其他方法可以进行正确的布局,但我已经按照您的方法进行了一些改动。它将在NextButton角落和TOP|RIGHTon BackButton角落上显示Bottom|Left。就像你想要的那样。您可以根据自己的要求进行更改。

© www.soinside.com 2019 - 2024. All rights reserved.