在我的 Activity 中,我有 2 个 TextView 。我需要拉伸(stretch) textview2 的高度以填充屏幕。我的 TextView 位于以 ScrollView 为根的相对布局内。即使我提到 as match_parent 它也没有填充屏幕而是作为wrap_content。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/scrollView1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="20dp"
tools:context=".CoupansActivity"
android:background="@drawable/back_ground">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:textSize="20dp"
android:text="COUPONS" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:background="@drawable/back"
android:gravity="center"
android:text="Some text" />
</RelativeLayout>
</ScrollView>
最佳答案
尝试以下操作:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="20dp"
tools:context=".CoupansActivity"
android:background="@drawable/back_ground">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:textSize="20dp"
android:text="COUPONS" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/textView1"
android:layout_alignParentBottom="true"
android:layout_marginTop="23dp"
android:background="@drawable/back"
android:gravity="center"
android:text="Some text" />
</RelativeLayout>
如果布局中只有两个 TextView
,我认为 ScrollView
是不必要的。
关于android - ScrollView 内的 TextView 未填充屏幕高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16420336/