2016-03-10 3 views
0

У меня есть относительная компоновка с 6 картами в ней. Это мой xml-код:android - удалить границу между элементами в относительной компоновке

<?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="fill_parent" 
android:layout_height="match_parent" 
android:padding="0dp"  
android:layout_margin="0dp" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
> 
<View android:id="@+id/view" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_centerHorizontal="true"/> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/Card_View1" 
    android:layout_width="0dp" 
    android:layout_height="190dp" 
    android:layout_alignLeft="@id/view" 
    android:layout_alignParentRight="true" 
    android:onClick="openFirst" 
    > 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:src="@drawable/icontest" 
     /> 
</android.support.v7.widget.CardView> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/Card_View2" 
    android:layout_gravity="center" 
    android:layout_toRightOf="@+id/Card_View1" 
    android:layout_width="0dp" 
    android:layout_height="190dp" 
    android:layout_alignRight="@id/view" 
    android:layout_alignParentLeft="true" 
    android:onClick="openFirst" 
    > 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView2" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:src="@drawable/icontest"/> 
</android.support.v7.widget.CardView> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/Card_View3" 
    android:layout_gravity="center" 
    android:layout_below="@+id/Card_View1" 
    android:layout_width="0dp" 
    android:layout_height="190dp" 
    android:layout_alignRight="@id/view" 
    android:layout_alignParentLeft="true" 
    > 
</android.support.v7.widget.CardView> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/Card_View4" 
    android:layout_gravity="center" 
    android:layout_toRightOf="@+id/Card_View3" 
    android:layout_below="@+id/Card_View2" 
    android:layout_width="0dp" 
    android:layout_height="190dp" 
    android:layout_alignLeft="@id/view" 
    android:layout_alignParentRight="true" 
    > 
</android.support.v7.widget.CardView> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/Card_View5" 
    android:layout_gravity="center" 
    android:layout_below="@+id/Card_View3" 
    android:layout_width="0dp" 
    android:layout_height="190dp" 
    android:layout_alignRight="@id/view" 
    android:layout_alignParentLeft="true" 
    > 
</android.support.v7.widget.CardView> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/Card_View6" 
    android:layout_gravity="center" 
    android:layout_below="@+id/Card_View4" 
    android:layout_toRightOf="@+id/Card_View5" 
    android:layout_width="0dp" 
    android:layout_height="190dp" 
    android:layout_alignLeft="@id/view" 
    android:layout_alignParentRight="true" 
    > 
</android.support.v7.widget.CardView> 
</RelativeLayout> 

В Android Studio все элементы находятся рядом друг с другом. Нет границ, ничего. Когда я запускаю приложение на своем телефоне (Sony Xperia T), между картами есть черная рамка. Как удалить границу? Я хочу, чтобы карты занимали все пространство на экране.

ответ

0

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

Что-то вроде 2 горизонтальных линейных макетов, каждый с весом 1 (так что они занимают половину экрана каждый), внутри вертикальной линейной компоновки (чтобы они были друг на друге). Затем в каждом из этих 2 используйте еще три линейных макета, также каждый из которых имеет значение layout_weight, равное 1, поэтому каждый из них занимает 1/3 от ширины их родителя. Для каждого из самых внутренних линейных макетов установите ширину и высоту в 0, и вес позаботится об этом.

Наконец, в каждом из 6 самых внутренних LinearLayouts разместите один CardView и установите его ширину и высоту в match_parent. Таким образом, вы должны получить ваш экран разделен на 6 даже куски карт без пробелов Разногласия между ними, и он будет работать на различных устройствах (ваш будет не потому, что вы жёстко значения):

android:layout_height="190dp" 

Это то, что вызывает его выглядят по-разному на эмуляторе и на вашем телефоне (и, возможно, даже на другом телефоне).

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