2016-08-20 2 views
1

Я пытаюсь использовать RelativeView как часть RecyclerView. Но пользовательский интерфейс отображается неправильно. Ниже XML, который я использую для RelativeLayoutAndroid RelativeLayout UI не отображается правильно

<?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> 

Когда я запустить его в эмуляторе я под дисплеем Emulator view

Как я учусь андроида программирования я не получаю то, что может быть причиной того, что элемент не указан ниже каждого элемента, и между двумя предметами есть много разрыва.

+0

Каков ожидаемый вид? – Karacago

+0

android: padding = "4dp", дает отступы на каждые 4 направления. у вас есть 2 textview padding 4, поэтому он имеет 2 x 4 = 8 отступов между двумя текстовыми полями. – Karacago

ответ

1

Просто измените высоту RelativeLayout от match_parent до wrap_content. то есть

<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"> 
Смежные вопросы