Reputation: 20656
I'm trying to design a Layout
wich is like this image :
I thought that the best way would be using LinearLayout
for each item, and I was wrong, because it looks like this :
And the problem is the ImageView
that is not in the middle, I tried to put it with margins, but when I try to launch this APP on a Samsung s2 it mess the Layout
and on my Lg g3 the ImageView
I see on the bottom (without margin) and on s2 I see it on the middle...
This is my layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="5dp"
android:layout_margin="7dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/LinearImageView">
<ImageView android:id="@+id/image_holder"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitXY" />
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/LinearImageView"
android:background="@android:color/darker_gray"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/LinearTitulo"
android:layout_below="@+id/divider"
android:layout_marginLeft="5dp"
>
<TextView
android:id="@+id/info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SOME TEXT HERE"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/LinearPrice"
android:layout_marginLeft="5dp"
android:layout_below="@+id/LinearTitulo">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvPrice"
android:text="SOME TEXT HERE"
android:layout_below="@+id/info_text"/>
</LinearLayout>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@mipmap/ic_launcher"
android:layout_marginRight="5dp"
android:layout_alignBottom="@+id/LinearPrice"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
I thought that a GridView
would be the point, and I saw a library like AsymmetricGridView
but it's not what I need because you put it by code (java), and I don't want it.
I suppose that is a GridView
with two columns, the first column has 2 rows and the second has one row, but I don't know if it's the best approach, could you guide me?
Upvotes: 0
Views: 152
Reputation: 784
How about this as a reference:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#111">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="#fff"
android:textSize="18sp"
android:text="TextView1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:padding="10dp"
android:textSize="18sp"
android:text="TextView2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right">
<ImageView
android:layout_width="50sp"
android:layout_height="50sp"
android:layout_gravity="center"
android:background="@drawable/placeholder_loader"
/>
</LinearLayout>
</LinearLayout>
Upvotes: 1
Reputation: 4213
Here's another layout without fussing with Relative positioning. I use a similar layout in one of my apps and it works fine, though you'll probably want to season to your own taste ;)
<android.support.v7.widget.CardView
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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#000000" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#000000" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@android:color/black" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="10dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
Edit: added pic of output
Upvotes: 3
Reputation: 17142
Try this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="7dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="@+id/LinearImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_holder"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitXY"/>
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/LinearImageView"
android:background="@android:color/darker_gray"/>
<LinearLayout
android:id="@+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/divider">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="80">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text 1"
android:id="@+id/textView3"
android:textSize="40sp"
android:paddingLeft="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text2"
android:id="@+id/textView4"
android:textSize="20sp"
android:paddingLeft="30dp"/>
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_action_armchair"
android:layout_weight="20"/>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
Upvotes: 2
Reputation: 1852
Remove android:layout_alignBottom="@+id/LinearPrice"
and add android:layout_centerVertical="true"
to your ImageView
Upvotes: 1