2013-05-07 74 views
2

在我的活动中,我有2个文本视图。我需要拉伸textview2的高度来填充屏幕。我的textview是在scrollview的相对布局中作为根。即使我提到了match_parent它不是填满屏幕,而是以wrap_content的形式呈现。滚动视图中的textview不填充屏幕的高度

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

fill_parent呢?应该做这项工作。 – sandkasten 2013-05-07 13:33:19

+0

@sandkasten自从API 8开始,'fill_parent'已被弃用,以支持'match_parent'。 – TronicZomB 2013-05-07 13:34:09

+0

哦,我创建的最后一个应用都是API 7,所以不知道这个改变^^ – sandkasten 2013-05-07 13:36:08

回答

1

尝试以下操作:

<?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的I不认为ScrollView是必要的。

+0

我需要横向模式的滚动视图来查看textview中的全部内容。所以请使用滚动视图向我发送答案。 - – user2201685 2013-05-13 11:09:49

+0

@ user2201685你需要'TextView'滚动还是只有一个? – TronicZomB 2013-05-13 12:07:26

+0

@TronicZomB,...似乎在该滚动查看下的textview并没有改变...... – gumuruh 2014-07-19 06:58:59

1

试试这个,这应该工作..

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

<ScrollView 

android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" 
android:id="@+id/scrollView1"> 

<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" /> 
</ScrollView> 

</RelativeLayout> 
+0

对不起!它不会工作,因为scrollview可以只有一个孩子在里面..但我有2 textview – user2201685 2013-05-13 11:07:54

+0

然后你可以使用两个滚动查看每个textView ... – Saad 2013-05-13 11:13:02

0
.... <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">.... 

删除如下因素,你会有更好的效果:

  android:paddingLeft="20dp" 
      android:paddingTop="10dp" 
      android:paddingRight="20dp" 
      android:paddingBottom="20dp" 
+0

对不起!它没有任何区别... – user2201685 2013-05-13 11:12:24

相关问题