2016-09-27 36 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> 

希望它有幫助。