Reputation: 1063
I am trying to get the image at center of the imageviews named divider1,divider2 and divider3. But all I am getting is this:-
As you can see between the score and comment the image is little bit upwards shifted. The image is a 5x5 pixel 'dot'.
My XML file:-
<?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="match_parent"
android:orientation="vertical"
android:background="#d3d3d3"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded">
<TextView
android:id="@+id/list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:padding="2dp"/>
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp">
<TextView
android:id="@+id/list_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp" />
<ImageView
android:id="@+id/divider1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/divider"
android:scaleType="centerInside"
android:padding="2dp"/>
<TextView
android:id="@+id/list_domain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp" />
<ImageView
android:id="@+id/divider2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/divider"
android:scaleType="centerInside"
android:padding="2dp"/>
<TextView
android:id="@+id/list_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp"/>
</LinearLayout>
<ImageView
android:id="@+id/list_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="@+id/ll2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp" >
<TextView
android:id="@+id/list_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp" />
<ImageView
android:id="@+id/divider3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/divider"
android:scaleType="centerInside"
android:padding="2dp"/>
<TextView
android:id="@+id/list_comments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Any Ideas what is wrong?
Upvotes: 1
Views: 582
Reputation: 24205
The image view is wrapping depend on it's content
android:layout_width="wrap_content"
Set the image view height to match the container. and then you centre the image inside:
<ImageView
android:id="@+id/divider3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/divider"
android:padding="2dp"/>
Set those in your imageView.
Upvotes: 1