Reputation: 21
hey I'm doing an android app, someone can tell me why is not showing button mi_perfil on my andriod screen? this is my layout code:
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
<ImageView
android:id="@+id/foto"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginRight="6dip"
android:layout_marginLeft="20dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:gravity="center_horizontal"
android:layout_toRightOf="@id/linearLayout"
android:orientation="vertical" >
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="34dp"
/>
<TextView
android:id="@+id/txt4"
android:layout_width="match_parent"
android:layout_height="34dp"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="34dp"
android:text="@string/Importar_Contactos" />
</LinearLayout>
<Button android:id="@+id/miPerfil"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="@string/boton_mi_perfil"
android:onClick="MiPerfil"
android:layout_marginRight="20dip"
android:layout_marginLeft="6dip" />
</LinearLayout>
I want to put the button on the right of my screen, but it doesn't appears.
Thanks.
Upvotes: 0
Views: 105
Reputation: 11961
I have edited your XML according to your requirement.
<?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="fill_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:id="@+id/foto"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="20dip"
android:layout_marginRight="6dip" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/linearLayout"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="34dp" />
<TextView
android:id="@+id/txt4"
android:layout_width="match_parent"
android:layout_height="34dp" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/linearLayout"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="@+id/txt2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" Importar_Contactos" />
<Button
android:id="@+id/miPerfil"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="dsfsd" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Your button layout was with width and height match parent, that's why your button was hiding behind. I have used another child linearlayout.
Upvotes: 0
Reputation: 573
Please try it:
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:id="@+id/foto"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="20dip"
android:layout_marginRight="6dip"
android:background="@drawable/ic_launcher" />
<RelativeLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/linearLayout"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="34dp"
/>
<TextView
android:id="@+id/txt4"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="@+id/txt3"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="@+id/txt4"
android:text="Importar_Contactos" />
<Button
android:id="@+id/miPerfil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="6dip"
android:onClick="MiPerfil"
android:text="Button" />
</RelativeLayout>
</LinearLayout>
Upvotes: 0
Reputation: 573
please try this your button code inside in child linearLayout
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
<ImageView
android:id="@+id/foto"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginRight="6dip"
android:layout_marginLeft="20dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:gravity="center_horizontal"
android:layout_toRightOf="@id/linearLayout"
android:orientation="vertical" >
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="34dp"
/>
<TextView
android:id="@+id/txt4"
android:layout_width="match_parent"
android:layout_height="34dp"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="34dp"
android:text="@string/Importar_Contactos" />
<Button android:id="@+id/miPerfil"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="@string/boton_mi_perfil"
android:onClick="MiPerfil"
android:layout_marginRight="20dip"
android:layout_marginLeft="6dip" />
</LinearLayout>
Upvotes: 0
Reputation: 1723
Use RelativeLayout instead of the outer LinearLayout.
then you can arrange the image view to the left , and the button to the right.
Upvotes: 1