2016-10-03 5 views
0

私はRecyclerViewを使ってこれを何とかできました。 RecyclerViewで特定のアイテムのビューを作成すると、recyclerviewアイテムのレイアウトがparentに一致します。ScrollViewの最初のビューを画面に合わせることはできますか?

ScrollViewを使用してこれも可能なのでしょうか?ここで

は、私がこれまでにやったことだ:

ScrollViewのXML:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/scrollview_homescreen" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <LinearLayout 
     android:id="@+id/linearlayout_homescreen" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <include layout="@layout/listitem_comic_menu"/> 

     <LinearLayout 
      android:id="@+id/linearlayout_comic_listings" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

     </LinearLayout> 

    </LinearLayout> 

</ScrollView> 

内容:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativelayout_homescreen" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/imageview_menu_bg" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:adjustViewBounds="true" /> 

    <ImageView 
     android:id="@+id/imageview_menu_title_bg" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/starwars_webtoon_home_1_logo" 
     android:scaleType="fitXY" 
     android:adjustViewBounds="true" /> 

    <Button 
     android:id="@+id/button_start_reading" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_above="@+id/button_menu" 
     android:layout_marginBottom="18dp" 
     android:text="@string/button_start_reading" 
     android:gravity="start" 
     android:drawableRight="@drawable/ic_keyboard_arrow_right_black_24dp" 
     android:drawableEnd="@drawable/ic_keyboard_arrow_right_black_24dp" 
     android:background="@drawable/button_bg" 
     android:textSize="18sp" 
     android:layout_marginStart="12dp" 
     android:layout_marginLeft="12dp" 
     android:layout_marginEnd="12dp" 
     android:layout_marginRight="12dp" /> 

    <Button 
     android:id="@id/button_menu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="28dp" 
     android:text="@string/button_menu" 
     android:textSize="18sp" 
     android:textColor="#FFFFFF" 
     android:drawableLeft="@drawable/ic_menu_white_24dp" 
     android:drawableStart="@drawable/ic_menu_white_24dp" 
     android:background="?android:attr/selectableItemBackground" /> 

</RelativeLayout> 

それでは、私がやろうとしていますか?基本的にこれは漫画上のリストです。最初の項目は、ホーム画面、こことそこに2つのボタンとアプリケーションのロゴ全体でなければなりません。次の項目には、リスト(私は同じ幅と高さの40項目があります)とフッターが表示されます。

画面の親と一致するように私のホーム画面が必要です。したがって、最上部をスクロールすると、最初の項目(ホームスクリーンである最初のビュー)がデバイスの画面全体を塗りつぶします。

私はRecyclerViewでこれを行うことができ、うまく見えました。私は、私がシステムをハックしているところまで広範囲に修正しなければならない問題を抱えていました。私は、RecyclerViewがこのような場合に最適なレイアウトではないことを認識しています。私は現在、ScrollViewに切り替えて、動的に/静的に漫画アイテムを追加するかどうかを決定しています。しかし、最初のビューであるホームスクリーンはスクリーンデバイスと一致しません。

ScrollViewでこれを行うことができますか?

ありがとうございます!

+0

あなたは "重力" 属性 –

+0

@Saretを使用する必要がありますが、あなたは例を提供してくださいできますか?実際に私が次元を求めているときに重力がここでどのように役立つかを理解するためにはまだ苦労しています。 –

+1

私は重力ではなく「重量」を意味していました。 listitem_comic_menuの相対レイアウトにandroid:weight = "1"を追加することができます。 –

答えて

1

使用重量属性:

<LinearLayout 
    android:id="@+id/linearlayout_homescreen" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="vertical"> 

     <include layout="@layout/listitem_comic_menu"/> 

     <LinearLayout 
      android:id="@+id/linearlayout_comic_listings" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

     </LinearLayout> 

</LinearLayout> 
+0

layout_weight https://developer.android.com/guide/topics/ui/layout/linear.html#Weight –

+0

申し訳ありませんが、 –

関連する問題