2016-08-20 27 views
1

RecyclerViewの一部としてRelativeViewを使用しようとしています。しかし、UIは適切に表示されません。以下は、私はエミュレータでそれを実行すると、私は私がその原因である可能性がありますどのようになっていないですアンドロイドプログラミングを学んでいたよう私が表示 Emulator viewAndroid RelativeLayoutのUIが正しく表示されない

の下に取得relativelayout

<?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:orientation="vertical"> 

    <CheckBox 
     android:id="@+id/list_item_crime_solved_check_box" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:padding="4dp"/> 

    <TextView 
     android:id="@+id/list_item_crime_title_text_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/list_item_crime_solved_check_box" 
     android:textStyle="bold" 
     android:padding="4dp" 
     tools:text="Crime Title"/> 

    <TextView 
     android:id="@+id/list_item_crime_date_text_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/list_item_crime_solved_check_box" 
     android:layout_below="@id/list_item_crime_title_text_view" 
     android:padding="4dp" 
     tools:text="Crime Date"/> 

</RelativeLayout> 

のために使っていたXMLですその商品は各商品の下に掲載されておらず、2つの商品の間には大きなギャップがあります。

+0

予想されるビューは何ですか? – Karacago

+0

android:padding = "4dp"は、4方向ごとにパディングを行います。 2つのtextviewパディング4があるので、2つのtextviewの間に2 x 4 = 8のパディングがあります。 – Karacago

答えて

1

ちょうどwrap_contentにmatch_parentからRelativeLayoutの高さを変更するレイアウトの高さを更新します。すなわち

<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="wrap_content"> 
1

ちょうどwrap_contentコードスニペット以下を参照、

<?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="wrap_content" 
    android:background="#ff0000" 
    android:orientation="vertical"> 
関連する問題