2015-03-17 3 views
0
Android Studio 1.2 

Здравствуйте,Использование относительно компоновки с регулировкой и выравнивание выдает

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

Проблема, я не могу получить правильность выравнивания. Это то, что у меня есть: enter image description here

И ниже является каркасный, что я разработал и то, что выше, должно выглядеть следующим образом:

enter image description here

Дата и время в порядке. Во-первых, это просто выравнивание Correct 20 и Incorrect 18 Они должны быть выровнены вправо. Во-вторых, thumbs up и thumbs down Насколько я не изменяю их размер, я не могу их выровнять, как каркас.

Большое спасибо за любые предложения,

Просто быстрый вопрос, конструкция выглядит очень скучный, любые предложения, чтобы сделать его немного более сексуально;)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeightLarge" 
    android:padding="8dp"> 

    <TextView 
     android:id="@+id/tvDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="16 Mar 2015" 
     android:textSize="18sp"/> 

    <TextView 
     android:id="@+id/tvTime" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentBottom="true" 
     android:text="22:15" 
     android:textSize="18sp"/> 

    <TextView 
     android:id="@+id/tvCorrectTxt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:gravity="left" 
     android:text="Correct 20" 
     android:textSize="18sp"/> 

    <TextView 
     android:id="@+id/tvIncorrect" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:gravity="left" 
     android:text="Incorrect 18" 
     android:textSize="18sp"/> 

    <ImageView 
     android:id="@+id/ivArrow" 
     android:layout_width="15dp" 
     android:layout_height="30dp" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="20dp" 
     android:src="@drawable/ic_action_next_item" 
     android:scaleType="center"/> 

    <ImageView 
     android:id="@+id/ivCorrect" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/ivArrow" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_action_good"/> 

    <ImageView 
     android:id="@+id/ivIncorrect" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/ivArrow" 
     android:layout_alignParentBottom="true" 
     android:src="@drawable/ic_action_bad"/> 

</RelativeLayout> 

ответ

1

Я хотел бы использовать LinearLayout с весами для TextViews. Что-то вроде этого:

Layout

Или вы можете попробовать GridLayout или Support GridLayout.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.GridLayout 
    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="wrap_content" 
    android:layout_gravity="center" 
    app:rowCount="2" 
    app:orientation="vertical"> 

    <TextView 
     app:layout_gravity="center_vertical|left" 
     android:text="16 Mar 2015"/> 

    <TextView 
     app:layout_gravity="center_vertical|left" 
     android:text="22:15"/> 

    <TextView 
     app:layout_gravity="center_vertical|right" 
     android:text="Correct 20"/> 

    <TextView 
     app:layout_gravity="center_vertical|right" 
     android:text="Incorrect 18"/> 

    <ImageView 
     app:layout_gravity="center|bottom" 
     android:src="..." /> 
    <ImageView 
     app:layout_gravity="center|bottom" 
     android:src="..."/> 

    <ImageView 
     app:layout_gravity="center_vertical" 
     app:layout_rowSpan="2" 
     android:src="..."/> 

</android.support.v7.widget.GridLayout> 

Возможно, вам понадобятся дополнительные поля или еще можно попробовать весы. Я не думаю, что весы вызовут проблему с производительностью, пока вы используете шаблон ViewHolder.

+0

Я действительно пытался сделать это без вложенных линейных макетов по соображениям производительности. – ant2009

+0

@ ant2009 см. Обновленный ответ. – MightySeal

1

Изменение относительной основной макет в LinearLayout и внутри LinearLayout использовать Relative Layout, как показано ниже

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeightLarge" 
    android:padding="8dp"> 
<RelativeLayout 
android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeightLarge" 
    android:padding="8dp"> 
    <TextView 
     android:id="@+id/tvDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="16 Mar 2015" 
     android:textSize="18sp"/> 

    <TextView 
     android:id="@+id/tvTime" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentBottom="true" 
     android:text="22:15" 
     android:textSize="18sp"/> 

    <TextView 
     android:id="@+id/tvCorrectTxt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:gravity="left" 
     android:text="Correct 20" 
     android:textSize="18sp"/> 

    <TextView 
     android:id="@+id/tvIncorrect" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:gravity="left" 
     android:text="Incorrect 18" 
     android:textSize="18sp"/> 

    <ImageView 
     android:id="@+id/ivArrow" 
     android:layout_width="15dp" 
     android:layout_height="30dp" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="20dp" 
     android:src="@drawable/ic_action_next_item" 
     android:scaleType="center"/> 

    <ImageView 
     android:id="@+id/ivCorrect" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/ivArrow" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_action_good"/> 

    <ImageView 
     android:id="@+id/ivIncorrect" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/ivArrow" 
     android:layout_alignParentBottom="true" 
     android:src="@drawable/ic_action_bad"/> 

</RelativeLayout> 
</LinearLayout> 
+0

Все еще не выровняли текст правильно и неправильно. Но все равно спасибо. – ant2009

1

Вы можете использовать GridLayout или TableLayout там, так как вашей деятельности действительно необходимо организовать эти данные таким образом.

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