2016-09-27 1 views
0

Давайте начнем со скриншотами я должен подготовиться к этому вопросуScrollView с целью высоты 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 для fillViewport = "true" и установить RelativeLayout на высоту "match_parent" вместо "wrap_content"? Возможно, я не понимаю, какое представление вы пытаетесь изменить. –

+0

@ChadSchultz Я использую fillViewport = "true" в scrollview и устанавливаю RelativeLayout в height "match_parent, но все тот же результат. Мне нужно, чтобы relativelayout, заполнить parrent по вертикали, но не влиять на прокрутке – Omid

+0

@ChadSchultz я могу использовать framelayout под scrollview и установить ширину этого как ширину моего 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> 

Надеюсь, это поможет.

Смежные вопросы