android button layout not appears - android

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.

Use RelativeLayout instead of the outer LinearLayout.
then you can arrange the image view to the left , and the button to the right.

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>

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>

Change your orientation to "vertical".
Than it works fine.

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.

Related

Linear layout or ImageView blackout

I have LinearLayout that contains 3 ImageButtons, I want to blackout background.
Also I have ImageView can I blackout it on top or no?
Or i want to use something else?
How I can do it?
My XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="267.9dp"
android:layout_gravity="center_horizontal"
android:id="#+id/frameLayout1">
<ImageView
android:src="#drawable/fone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:gravity="center"
android:id="#+id/imageView1" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:id="#+id/linearLayout1"
android:layout_marginBottom="0.0dp">
<ImageButton
android:src="#drawable/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/privateButton"
android:layout_marginRight="85.9dp"
android:background="#00000000"
android:layout_marginTop="11.5dp"
android:layout_marginLeft="4.6dp" />
<ImageButton
android:src="#drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/logoButton"
android:layout_marginTop="5.5dp"
android:layout_marginLeft="4.6dp"
android:layout_marginRight="91.7dp"
android:background="#00000000" />
<ImageButton
android:src="#drawable/cart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/cartButton"
android:background="#00000000"
android:layout_marginTop="11.5dp" />
</LinearLayout>
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="142.7dp"
android:layout_gravity="center_horizontal"
android:id="#+id/linearLayout2"
android:background="#ffffff">
<Button
android:text="Суші"
android:layout_width="185.8dp"
android:layout_height="fill_parent"
android:gravity="center"
android:id="#+id/button1"
android:background="#drawable/sushi"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp" />
<Button
android:text="Роли"
android:layout_width="178.8dp"
android:layout_height="fill_parent"
android:gravity="center"
android:id="#+id/button2"
android:background="#drawable/rolli"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginBottom="1dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_gravity="center_horizontal"
android:layout_height="142.7dp"
android:id="#+id/linearLayout3"
android:background="#ffffff">
<Button
android:text="Сети"
android:layout_width="185.8dp"
android:layout_height="match_parent"
android:gravity="center"
android:id="#+id/button3"
android:background="#drawable/sets"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginRight="1dp" />
<Button
android:text="Холодні Закуски"
android:gravity="center"
android:layout_width="178.8dp"
android:layout_height="match_parent"
android:id="#+id/button4"
android:background="#drawable/holodni"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:id="#+id/linearLayout4"
android:layout_marginLeft="0.0dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:background="#f2565c"
android:id="#+id/linearLayout5">
<ImageButton
android:src="#drawable/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/previousButton"
android:layout_marginRight="137.8dp"
android:background="#00000000"
android:layout_marginTop="17.8dp"
android:clickable="true"
android:layout_marginLeft="13.8dp" />
<ImageButton
android:src="#drawable/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/homeButton"
android:layout_marginRight="121.8dp"
android:background="#00000000"
android:layout_marginTop="13.6dp"
android:clickable="true" />
<ImageButton
android:src="#drawable/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/nextButton"
android:layout_marginLeft="0.0dp"
android:background="#00000000"
android:layout_marginTop="17.8dp"
android:clickable="true" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thank's for help!
This is how you put semitransparent black color. enter background attribute like this:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#AARRGGBB"
android:layout_gravity="center_horizontal"
android:id="#+id/linearLayout1"
android:layout_marginBottom="0.0dp">
For more info how to get semi-transparent color see this question and answer.
Android Dialog Semi-Transparent
Hope it helps!

Place button below editfield in relative layout

Hi all I have to add 2 Buttons below editfield. I had tried it using relativelayout. But it is not added exactly below mention position.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/des"
android:padding="10dip">
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/submit"
android:text="Cancel" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Here I want to add these two buttons exactly below "des" editfield. Thanks in advance
Currently it displays like . But I want these two buttons exactly below last editfield with equal size.
You have just add on your relative layout:
layout_gravity on right and width make on wrap_content. like this
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#id/des" android:layout_gravity="right"
android:padding="10dip">
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/submit"
android:text="Cancel" />
</RelativeLayout>
Output looks like:
Ist think you are doing wrong is that : ScrollView never contains Relative Layout as a direct child. it use LinearLayout as a direct child .
use this code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/des"
android:orientation="horizontal"
android:padding="10dip" >
<Button
android:id="#+id/submit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Try this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/des"
android:padding="10dip">
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Cancel" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/cancel"
android:text="Submit" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Try this:
One more thing when you want to do stuff like this, try to see in graphical layout and move elements in that to position you want. Most of time it will work as expected and you can get idea of place too.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/des"
android:padding="10dip" >
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/submit"
android:layout_alignBottom="#+id/submit"
android:layout_alignParentRight="true"
android:text="Cancel" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
In your case its not possible because you are trying to place a button relative to EditText which is placed inside a LinearLayout, you can place the button relative to linearlayout but not its ChildViews.
Try to bring all the Views inside a single relative layout and place all the Views relative to each other.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="User Name"
android:textStyle="bold" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:text="Description"
android:textStyle="bold" />
<EditText
android:id="#+id/des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/des"
android:padding="10dip" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:text="Submit" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
Hope this will solve your problem
android:layout_below="#id/des" That des is present in LinearLayout, IF you want to give that way, Same RelativeLyout should be given within the layout that des is present and Their parent should be relative layout, to use parementers such as below or above(i.e., with relative to other widget)

Image view with textviews in the linearlayout android

Am new to android UI designing.I want to implement the view (like in the image) into the specified linear layout. please help to sort me out.
<Linear Layout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/header" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
?????????????????????????????
</LinearLayout>
<ImageView
android:id="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:contentDescription="#string/dash_progress"
android:scaleType="fitXY"
android:src="#drawable/account_progress" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true" >
</ListView>
This the desired view i need
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dip"
android:layout_height="100dip"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="0.5"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_launcher"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/common_signin_btn_icon_dark" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="TextView" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_forward" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_plusone_medium_off_client" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Opthalmologist"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:text="UK" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Check this or you can do this with RelativeLayout simply
You need a RelativeLayout.
It is the best way to position your components this way.

layout buttons are not the same size in android

I have two questions, the first is that I would like the buttons to be on the bottom corner of the screen stacked like they are (they currently are in the middle) and I would like them to be the same size, currently the top 2 buttons are bigger then the bottom two buttons. Also maybe lowering the texview boxes down a little if that is easy enough.
<?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="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center" >
<EditText
android:id="#+id/playerLifeOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/badd1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+1" />
<Button
android:id="#+id/badd5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/bsub1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/bsub5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center" >
<EditText
android:id="#+id/playerLifeTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="right"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2add1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+1" />
<Button
android:id="#+id/b2add5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2sub1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/b2sub5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Check now.
<?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="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center" >
<EditText
android:id="#+id/playerLifeOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/badd1"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="+1" />
<Button
android:id="#+id/badd5"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/bsub1"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/bsub5"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center" >
<EditText
android:id="#+id/playerLifeTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" />
</LinearLayout>
<LinearLayout
android:layout_width="156dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2add1"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="+1" />
<Button
android:id="#+id/b2add5"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/b2sub1"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/b2sub5"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
All buttons should look like this one.-
<Button
android:id="#+id/badd5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+5" />
Check layout_width and layout_weight properties.
As for the EditTexts, you have several options, an easy one would be applying some top margin.-
<EditText
android:id="#+id/playerLifeOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" >
just a tip: using a RelativeLayout would give you more flexibility and a more simple possibility to achieve what you need.
Note: in my sample project the Holo.Light theme is applied, that's why it looks a bit different.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<!-- this is a SAMPLE layout. Adjust the values as you need them. -->
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="#000000"
android:orientation="vertical" >
</LinearLayout>
<EditText
android:id="#+id/editText1"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:ems="10" >
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:ems="10" >
<requestFocus />
</EditText>
<!-- do the same thing on the right side -->
<Button
android:id="#+id/btnMinOneLeft"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="-1" />
<Button
android:id="#+id/btnMinFiveLeft"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/btnMinOneLeft"
android:text="-5" />
<Button
android:id="#+id/btnPlusOneLeft"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_above="#+id/btnMinOneLeft"
android:layout_alignParentLeft="true"
android:text="+1" />
<Button
android:id="#+id/btnPlusFiveLeft"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_above="#+id/btnMinFiveLeft"
android:text="+5"
android:layout_toRightOf="#+id/btnPlusOneLeft"/>

How to Get a Framelayout wrap_content till the horizontalScrollview

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/quickaction_shadow_horiz"
android:paddingRight="#dimen/quickaction_shadow_horiz">
<FrameLayout
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip">
<LinearLayout
android:id="#+id/quickaction_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/quickaction_top_frame"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/quickaction_icon"
android:layout_width="54dip"
android:layout_height="57dip"
android:layout_marginLeft="15dip"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:scaleType="center"
android:visibility="gone" />
<LinearLayout
android:id="#+id/quickaction_header_content"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="#+id/quickaction_primary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:ellipsize="marquee"
android:textColor="#android:color/primary_text_light"
android:textStyle="bold"
android:textSize="18dip"
android:visibility="gone" />
<TextView
android:id="#+id/quickaction_secondary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/secondary_text_light"
android:textSize="15dip"
android:layout_marginTop="-3dip"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<HorizontalScrollView
android:id="#+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fadingEdgeLength="0dip"
android:background="#drawable/quickaction_slider_background"
android:scrollbars="none">
<LinearLayout
android:id="#+id/quickaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dip"
android:paddingBottom="4dip"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/quickaction_slider_grip_left" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/quickaction_slider_grip_right" />
</LinearLayout>
</HorizontalScrollView>
<FrameLayout
android:id="#+id/footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/scroll"
android:background="#drawable/quickaction_bottom_frame" />
<!-- <LinearLayout
android:id="#+id/footer_disambig"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scroll"
android:background="#drawable/quickaction_disambig_bottom_bg"
android:orientation="vertical"
android:visibility="gone">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#color/quickaction_disambig"
android:divider="#drawable/quickaction_disambig_divider"
android:cacheColorHint="#null" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dip"
android:layout_marginRight="19dip"
android:minHeight="60dip"
android:textColor="#f000"
android:textStyle="bold"
android:text="Remember Choice"
android:textAppearance="?android:attr/textAppearanceSmallInverse"
android:button="#drawable/quickaction_disambig_checkbox" />
</LinearLayout> -->
<ImageView
android:id="#+id/arrow_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/quickaction_arrow_up" />
<ImageView
android:id="#+id/arrow_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-1dip"
android:layout_below="#id/footer"
android:src="#drawable/quickaction_arrow_down" />
<!-- <ImageView
android:id="#+id/arrow_down_stub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-1dip"
android:layout_below="#id/footer_disambig"
android:visibility="invisible"
android:src="#drawable/quickaction_arrow_down" />-->
</RelativeLayout>
Hello i want my Framelayout to be of same width as of the Horizontalscrollview i does not take the width of the Horizontalscrollview just stays there at the start postion if given wrap_content but takes the fill_parent i want to keep wrap_content how can i do that?
Add below two lines inside <HorizontalScrollView> and give it a try:
android:layout_alignLeft="#id/header"
android:layout_alignRight="#id/header"
hope this helps.

Categories

Resources