2016-09-27 60 views
0

一个match_parent高度视图让我们先从截图我已经在此布局这个问题滚动型与内

1enter image description here

准备,也许这一面大旗不存在,所以它的皮,你在看其他图片。 此布局的一部分包含文本,因此我想将孔内容滚动到一起,但我希望文本下的背景高度充满我的屏幕,并且不会影响滚动,因此滚动文本太长时必须激活,或者旗帜的高度更大。

这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".NewsActivity" 
    tools:showIn="@layout/activity_news"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:orientation="vertical" 

    android:layout_height="wrap_content"> 
    <ImageView 
     android:id="@+id/bigPicture" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:contentDescription="@null" 
     android:scaleType="fitXY" 
     android:src="@drawable/tama_logo" /> 


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

     <de.hdodenhof.circleimageview.CircleImageView 
      android:id="@+id/largeIcon" 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="false" 
      android:layout_alignWithParentIfMissing="false" 
      android:src="@mipmap/ic_launcher" 
      android:layout_marginTop="8dp" 
      android:layout_marginRight="12dp" 
      android:layout_marginLeft="8dp" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:padding="8dp" 
       android:background="@drawable/shadow" 

       android:id="@+id/messageBody" 
       android:layout_toStartOf="@+id/largeIcon" 
       android:layout_toLeftOf="@+id/largeIcon"> 

       <TextView 
        android:id="@+id/title" 
        style="@style/news_activity_title" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:ellipsize="end" 
        android:maxLines="2" /> 

       <TextView 
        android:id="@+id/body" 
        style="@style/news_activity_body" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:ellipsize="end" 
        android:maxLines="2" /> 
      </LinearLayout> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/date" 
      android:layout_alignWithParentIfMissing="true" 
      android:maxLines="3" 
      android:text="1369/12/25 22:45:32" 
      android:textColor="#aaa" 
      android:textSize="10sp" 
      android:singleLine="false" 
      android:gravity="center_horizontal" 
      android:textStyle="bold" 
      android:layout_below="@+id/largeIcon" 
      android:layout_toRightOf="@+id/messageBody" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:layout_marginRight="5dp" /> 

    </RelativeLayout> 
</LinearLayout> 
</ScrollView> 

这幅画将explane我的期望,对不起我的英语不好:(

enter image description here

+0

关闭我的头顶,你是否尝试设置ScrollView而不是RelativeLayout来填充视口=“true”,并将RelativeLayout设置为高度“match_parent”而不是“wrap_content”?我可能会误解你想要改变的视图 –

+0

@ChadSchultz我在scrollview中使用fillViewport =“true”,并将RelativeLayout设置为高度“match_parent”,但仍然是相同的结果,我需要这个relativelayout,垂直填充边界但不影响在滚动 – Omid

+0

@ChadSchultz我可以在scrollview下使用framelayout,并将它的宽度设置为我编程的realativelayout的宽度?可以吗? – Omid

回答

1

检查下面的代码:

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

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:fillViewport="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <ImageView 
      android:id="@+id/bigPicture" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@null" 
      android:scaleType="fitXY" 
      android:src="@drawable/tama_logo" /> 

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


      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="4" 
       android:background="@android:color/white"> 

       <TextView 
        android:id="@+id/title" 
        style="@style/news_activity_title" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentTop="true" 
        android:ellipsize="end" 
        android:maxLines="2" /> 

       <TextView 
        android:id="@+id/body" 
        style="@style/news_activity_body" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_below="@+id/title" 
        android:ellipsize="end" 
        android:maxLines="2" /> 


      </RelativeLayout> 


      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="2"> 

       <de.hdodenhof.circleimageview.CircleImageView 
        android:id="@+id/largeIcon" 
        android:layout_width="48dp" 
        android:layout_height="48dp" 
        android:layout_alignParentEnd="true" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentTop="false" 
        android:layout_alignWithParentIfMissing="false" 
        android:layout_marginLeft="8dp" 
        android:layout_marginRight="12dp" 
        android:layout_marginTop="8dp" 
        android:src="@mipmap/ic_launcher" /> 


       <TextView 
        android:id="@+id/date" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentEnd="true" 
        android:layout_alignParentRight="true" 
        android:layout_alignWithParentIfMissing="true" 
        android:layout_below="@+id/largeIcon" 
        android:layout_marginRight="5dp" 
        android:gravity="center_horizontal" 
        android:maxLines="3" 
        android:singleLine="false" 
        android:text="1369/12/25 22:45:32" 
        android:textColor="#aaa" 
        android:textSize="10sp" 
        android:textStyle="bold" /> 

      </RelativeLayout> 


     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

希望它有帮助。