Question

I am displaying an image with text and button for single. It's working correctly. I want to add one more image with text and button. How to write the layout?

Next layout I want exactly the same as the first layout with changing positions and without using ListView I want to display.

Can anyone please help me?

xml

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


    <ImageView
        android:id="@+id/image1"
        android:layout_width="140dp"
        android:layout_height="103dp"
        android:src="@drawable/arun_arora_chairman" />

    <TextView
        android:id="@+id/name1"
        android:layout_width="134dp"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/click1"
        android:layout_alignParentTop="true"
        android:text="Arun Arora Chairman, Edvance Group"
        android:textSize="16dp" />

    <Button
        android:id="@+id/click1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/name1"
        android:layout_marginLeft="39dp"
        android:layout_toRightOf="@+id/image1"
        android:text="Readmore" />

</RelativeLayout>
Was it helpful?

Solution

Simply copy the Views again into the Relative Layout, but rename the IDs like so:

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

    <ImageView
        android:id="@+id/image1"
        android:layout_width="140dp"
        android:layout_height="103dp"
        android:src="@drawable/arun_arora_chairman" />

    <TextView
        android:id="@+id/name1"
        android:layout_width="134dp"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/click1"
        android:layout_alignParentTop="true"
        android:text="Arun Arora Chairman, Edvance Group"
        android:textSize="16dp" />

    <Button
        android:id="@+id/click1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/name1"
        android:layout_marginLeft="39dp"
        android:layout_toRightOf="@+id/image1"
        android:text="Readmore" />

    <ImageView
        android:id="@+id/image2"
        android:layout_width="140dp"
        android:layout_height="103dp"
        android:layout_below="@id/click1"
        android:src="@drawable/arun_arora_chairman" />

    <TextView
        android:id="@+id/name2"
        android:layout_width="134dp"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/click2"
        android:layout_alignTop="@id/click2"
        android:text="Arun Arora Chairman, Edvance Group"
        android:textSize="16dp" />

    <Button
        android:id="@+id/click2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/name2"
        android:layout_marginLeft="39dp"
        android:layout_toRightOf="@+id/image2"
        android:text="Readmore" />

</RelativeLayout>

If you would like to be more efficient, you could research into the tag here http://developer.android.com/training/improving-layouts/reusing-layouts.html

OTHER TIPS

if you want to add in the same layout go as paul told, if you cant view the any objects(button or image) make that relativelayout as a child to scrollview. take a look at this How to use ScrollView in Android?.

copy paste the following code,you will see the components.just adjust margins to set them where you want,and you can make their copies by just copying the xml but changing the id's and changing the poistions for the new views you are adding

    <ImageView
        android:id="@+id/image1"
        android:layout_width="140dp"
        android:layout_height="103dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="20dp"
        android:src="@drawable/arun_arora_chairman" />

    <ImageView
        android:id="@+id/image2"
        android:layout_width="140dp"
        android:layout_height="103dp"
        android:layout_marginLeft="110dp"
        android:layout_marginTop="200dp"
        android:src="@drawable/arun_arora_chairman" />

    <TextView
        android:id="@+id/name1"
        android:layout_width="134dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="300dp"
        android:text="Arun Arora Chairman, Edvance Group"
        android:textSize="16dp" />
  <TextView
        android:id="@+id/name2"
        android:layout_width="134dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="200dp"
        android:layout_marginTop="400dp"
        android:text="Arun Arora Chairman, Edvance Group"
        android:textSize="16dp" />

    <Button
        android:id="@+id/click1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
          android:layout_marginLeft="300dp"
        android:layout_marginTop="400dp"
        android:text="Readmore" />

    <Button
        android:id="@+id/click2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
          android:layout_marginLeft="500dp"
        android:layout_marginTop="130dp"
        android:text="Readmore" />

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top