0

I want to design following design in android using Linear layout enter image description here

I had written following code but not working

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/alert_dark_frame" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="2" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="TextView" android:layout_weight="1" /> <TextView android:id="@+id/textView2" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="TextView" /> </LinearLayout> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:hint="TestData"/> </LinearLayout> </LinearLayout> 

it gives me output like

enter image description here

can anyone pointout me.. where is problem???

7
  • 1
    whats the output u r getting look like? Commented Dec 6, 2012 at 12:49
  • could you pinpoint..what is the problem? what does but not working mean? Commented Dec 6, 2012 at 12:54
  • @ArchanA Is it compulsory to use LinearLayout? Commented Dec 6, 2012 at 12:56
  • @Dipak Keshariya no not compulsary to use linear layout Commented Dec 6, 2012 at 13:04
  • @ArchanA If you have any query regarding android you can tell me anytime. Commented Dec 6, 2012 at 13:34

5 Answers 5

3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/alert_dark_frame" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="2" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="dfasdfasdfasfasf" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="right" android:text="07 DEc" /> </LinearLayout> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="dskfhasjkldfhadjklsfhadjklsfhajkldfhadjklsfhajklsfhajklsdfhajklsdfhajklsdfhajkldf" /> </LinearLayout> </LinearLayout> 

This will work... :)

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

Comments

0

This will work for you.

<?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="#ffffff" android:padding="5dip" > <ImageView android:id="@+id/icon" android:layout_width="70px" android:layout_height="50px" android:layout_marginRight="3dip" android:src="@drawable/ic_launcher" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/toptext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxLines="1" android:text="dsggsdggfsgf" android:textColor="#000000" android:textSize="16px" android:textStyle="bold" /> <TextView android:id="@+id/datetext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:maxLines="1" android:text="1 dec 2012" android:textColor="#cccccc" android:textSize="12px" android:textStyle="bold" /> </RelativeLayout> <TextView android:id="@+id/bottomtext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="dsggsdggfsgfwaffgdgafgggfdgfdgsfgfdgdfsgdfdsggsdggfsgfwaffgdgafgggfdgfdgsfgfdgdfsgdfdsggsdggfsgfwaffgdgafgggfdgfdgsfgfdgdfsgdfdsggsdggfsgfwaffgdgafgggfdgfdgsfgfdgdfsgdf" android:textColor="#696969" android:textSize="12px" /> </LinearLayout> </LinearLayout> 

Comments

0

I think you can use relativelayout at first level, like the following:

<relativelayout> <imageview align to parent top, left, bottom> <linearlayout align to parent to, right, right to image view> <textview1/> <textview2/> </linearlayout> <textview align to parent bottom, right, righto to image view, below linearlayout> </relativelayout> 

Comments

0

This should work. But it will be better if you use RelativeLayout

<?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="wrap_content" android:layout_weight="1" android:background="@android:color/white" android:orientation="horizontal" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/alert_dark_frame" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:weightSum="2" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView" /> </LinearLayout> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="TestData" android:text="TextView" /> </LinearLayout> </LinearLayout> 

5 Comments

You can not use this android:layout_alignParentLeft="true", android:layout_alignParentRight="true" properties with LinearLayout.
Thanks! Copied that from author's layout
@Dipak Keshariya i can only use this(android:layout_alignParentLeft="true", android:layout_alignParentRight="true") with relative correct??
Yes, only with RelativeLayout
@Dipak Keshariya your answer is somewhat what i need..but i want textView2's value right side.
0
 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:weightSum="3" android:orientation="horizontal"> <ImageView android:id="@+id/imageView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@android:drawable/alert_dark_frame" android:layout_weight="2"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="3" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hfdfhfj" android:layout_weight="2" /> <TextView android:id="@+id/textView2" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6 Dec 2012" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="fkjfkdsnfdsnfkdsn\nmnfkfknfkdf\nfknf" android:hint="TestData"/> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> 

Try this code.it is exactly what you want.

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.