Reputation: 18143
I have a layout but the ImageView with @id/category_starred_icon
is not showed, the expected behavoir is expand the LinearLayout with the 2 TextView to all empty space avalaible, but the ImageView isn't showed
<?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="vertical"
android:background="@drawable/borders" >
<View
android:id="@+id/category_color"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/awazari_blue" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/category_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:textSize="18sp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:textColor="@android:color/black"
android:hint="@string/app_name" />
<TextView
android:id="@+id/category_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:maxLines="3"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textColor="@color/awazari_medium_gray"
android:ellipsize="end"
android:hint="@string/description" />
</LinearLayout>
<ImageView
android:id="@+id/category_starred_icon"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/unstarred"
android:contentDescription="@string/app_name"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 217
Reputation: 4314
use the below code it will exactly gave you what you want :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="First Textview" />
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Second Textview" />
</LinearLayout>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="@drawable/ic_launcher" />
</LinearLayout>
this is the output:
hope this help you .
Upvotes: 3
Reputation: 44571
I'm not sure exactly what you want without a screenshot or a description but your problem is that your ImageView
is inside a LienarLayout
with horizontal orientation
who has another child LinearLayout
with a horizontal orientation
who's width
is match_parent
, leaving no room for the ImageView
<LinearLayout
android:orientation="horizontal" <!-- This is the ImageViews parent -->
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent" <!-- This child is taking up all of the width -->
android:layout_height="wrap_content">
There are different things you can do here depending on what you want like removing one of the LinearLayout
s or giving it a vertical orientation
or using a RelativeLayout
. But I don't know what exactly you want so its hard to give a complete answer on that
Edit
You can see if this gives you what you want. Without a screenshot or better description its hard to know exactly where you want everything. But you could tweak this to your liking
<RelativeLayout
android:layout_width="match_parent" //changed this to a RelativeLayout
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/ll"
android:orientation="vertical"
android:layout_width="wrap_content" // changed the width here
android:layout_height="wrap_content">
<TextView
android:id="@+id/category_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:textSize="18sp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:textColor="@android:color/black"
android:text="Text" />
<TextView
android:id="@+id/category_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:maxLines="3"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:ellipsize="end"
android:text="Text Again"/>
</LinearLayout>
<ImageView
android:id="@+id/category_starred_icon"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/blue_box"
android:layout_gravity="right"
android:layout_alignParentRight="true" />
</LinearLayout>
Note that I changed the text of TextView
s, colors, and backgrounds just so I could display it on my editor
Upvotes: 0
Reputation: 1792
Your ImageView
is hidden because you are using android:orientation="horizontal"
both with layout with android:layout_width="match_parent"
.
It has hidden your ImageView
on the right side of inner LinearLayout
which is not visible.
You can use android:weight=1
to fill all free space apart of ImageView
by LinearLayout
.
Upvotes: 0