Android Developer Trainee Android Developer Trainee - 3 months ago 8
Android Question

How to make image in a list view place on then right side?

Image of My Layout

enter image description here

I'm having a list view with images. but the image is showing on the left side how can i place that image on the right side and change its size...

My XML code is..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/album1" />
<TextView
android:id="@+id/Itemname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="5dp"/>




My Mainactivity.java code is...

public class MainActivity extends ListActivity {

String[] itemname ={
"Safari",
"Camera",
"Global",
"FireFox",
"UC Browser",
"Android Folder",
"VLC Player",
"Cold War"
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

this.setListAdapter(new ArrayAdapter<String>(
this, R.layout.mylist,
R.id.Itemname,itemname));
}
}

Answer
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<ImageView
  android:id="@+id/icon"
  android:layout_alignParentEnd="true"
  android:layout_width="50dp"
  android:layout_height="50dp"
  android:layout_marginBottom="5dp"
  android:layout_marginLeft="5dp"
  android:layout_marginRight="5dp"
  android:layout_marginTop="5dp"
  android:src="@drawable/album1" />
<TextView
  android:id="@+id/Itemname"
  android:layout_alignParentStart="true"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textSize="20sp" 
  android:paddingTop="5dp"/>

</RelativeLayout>

Or you can swap your views in the LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<TextView
android:id="@+id/Itemname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" 
android:paddingTop="5dp"/>

<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/album1" />

</LinearLayout>
Comments