3

I am trying to create a layout in android, when i create a linear layout inside a linear layout its getting added but not visible in the interface. here is my code

<?xml version="1.0" encoding="utf-8"?> <!-- Parent linear layout with vertical orientation --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="_baseline" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dip" android:text="@string/name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_marginTop="0dp" android:ems="10" > <requestFocus /> </EditText> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="290dp" android:text="@string/submit" /> <!-- Child linear layout with horizontal orientation --> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#2a2a2a" android:baselineAligned="_baseline" android:orientation="horizontal" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Previous" android:padding="15dip" android:layout_weight="1" android:gravity="center"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Next" android:padding="15dip" android:layout_weight="1" android:gravity="center"/> </LinearLayout> </LinearLayout> 
7
  • There is no space for it, your EditText and Button are match_parent so pushing everything out. Commented Jun 25, 2013 at 9:17
  • 1
    android:orientation="horizontal" your parent layout has this property. change it to vertical Commented Jun 25, 2013 at 9:17
  • Thanks for the reply Ken,I did that change but still its not visible. Commented Jun 25, 2013 at 9:19
  • @BrijeshThakur i had it as vertical then the edittext comes in a separate line Commented Jun 25, 2013 at 9:20
  • Then How do you want it.. I will give you the working code. Commented Jun 25, 2013 at 9:21

5 Answers 5

2

Try this I think you want this type of UI.

<?xml version="1.0" encoding="utf-8"?> <!-- Parent linear layout with vertical orientation --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 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:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dip" android:text="@string/app_name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_marginTop="0dp" android:ems="10" > <requestFocus /> </EditText> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="290dp" /> <!-- Child linear layout with horizontal orientation --> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#2a2a2a" android:orientation="horizontal" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Previous" android:padding="15dip" android:layout_weight="1" android:gravity="center"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Next" android:padding="15dip" android:layout_weight="1" android:gravity="center"/> </LinearLayout> </LinearLayout> 

the prob. is that you want to TextView and EditText in single line for that you put parent LinearLayout in Horizontal orientation but because of that all content saperated in gorizontalway..

so, you need to parent Layout Orientation as Vertical and take new Layout in that for EditText and TextView for horizontal separation. and that new Layout you need in Horizontal Orientation.

Show your UI here:

UI based on Above code.

Sign up to request clarification or add additional context in comments.

Comments

2

Change the first Linear Layout orientation "vertical". It should be works..

Comments

1

Your parent layout is showing the child layout, but it is out of view. Change the Parent's layout orientation to Vertical and it will be visible.

Make these changes..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="_baseline" android:orientation="vertical" > 

To get edittext in the same line,

Create a child layout for textview and edittext and make its orientation as horizontal.. it will be in the same line

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="_baseline" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="_baseline" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dip" android:text="@string/name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_marginTop="0dp" android:ems="10" > <requestFocus /> </EditText> </LinearLayout> ... ... </LinearLayout> 

Comments

0

This is your description as you posted question, You done mistake in orientation, In Comment you write

< !-- Parent linear layout with vertical orientation -->

but in LinearLayout you set Orientation

android:orientation="horizontal"

make it to

android:orientation="vertical"

and your problem is solved.

Comments

0

try this...

<?xml version="1.0" encoding="utf-8"?> <!-- Parent linear layout with vertical orientation --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="_baseline" android:layout_weight="1" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dip" android:text="@string/name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_marginTop="0dp" android:ems="10" > <requestFocus /> </EditText> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="290dp" android:text="@string/submit" /> </LinearLayout> <!-- Child linear layout with horizontal orientation --> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#2a2a2a" android:layout_weight="1" android:baselineAligned="_baseline" android:orientation="horizontal" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Previous" android:padding="15dip" android:layout_weight="1" android:gravity="center"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Next" android:padding="15dip" android:layout_weight="1" android:gravity="center"/> </LinearLayout> </LinearLayout> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.