Im trying to make something similar to this - Android Layout(User Interface) only I want to make the first column with a weight of 4 the second one with a weight of 2 (and also with two rows) and the last one with a weight of 1 (and also with three rows)...problem is It messes up itself (I copy and pasted the answer and changed everything according to my needs but it keeps on get messed up.. =) any help?
[code]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background_color"
android:orientation="vertical"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/textDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="#string/dishes"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/seperator_size"
android:background="#color/seperator" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textfood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/food"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imagefood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/seperator_size"
android:background="#color/seperator" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/malls"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/seperator_size"
android:background="#color/seperator" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="3"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/seperator_size"
android:background="#color/seperator" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coupons"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/seperator_size"
android:background="#color/seperator" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/markets"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
[/code]
That is the result -
The result should look like -
Any help??
EDIT working example now
This is not a complete answer because the vertical dividers are still not working, but hopefully it gets you going in the right direction:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dishes"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#color/red" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textfood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Food"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imagefood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="5dp"
android:layout_height="fill_parent"
android:background="#color/red"
android:gravity="center" >
</View>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Malls"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#color/red" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="App name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="5dp"
android:layout_height="fill_parent"
android:background="#color/red"
android:gravity="center" >
</View>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coupons"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="5dp"
android:layout_height="fill_parent"
android:background="#color/red"
android:gravity="center" >
</View>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Markets"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
I'm not sure if this was just a mistake when you included your XML here, but you're missing a ">" after the parent LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background_color"
android:orientation="vertical"
Should be
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background_color"
android:orientation="vertical" >
Additionally, you are using weights in some of this parent layout's children, but you have not specified a weightSum total in the parent LinearLayout. Remember that a weightSum is the total weight to be distributed amongst the children, so their weights should add up to this weightSum. Also, just a head's up, but using nested weights (which you would be doing if you added that in) is bad for performance.
Maybe the best solution to your problem would be to explore a different layout option instead of using a LinearLayout? You could get it to work this way, though. Make the parent weightSum 7 and make sure you distribute this as desired to the children.
As per your picture (and using linear layouts), it should look something like this, I think:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="7" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weight="4" >
// This one's child here - it has weight 1.
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="2"
android:weight="2" >
// This one's children here - they both have weight 1.
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="3"
android:weight="1" >
// This one's children here - they all have weight 1.
Don't forget to close the LinearLayouts as well. I haven't tested that code, either, so you will want to review it for possible errors.
I'm not sure if this is your only problem but when using weight your layout_width should be "0dp" for a horizontal orientation and layout_height should be "0dp" for a vertical orientation. So for example your first child should be
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal" >
because it belongs to a parent LinearLayout who's orientation is vertical
Update
Something like this should get you really close. Note I had to take out your resources to make it work in my editor so you will just have to put those back in
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/textDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Dishes"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textfood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Food"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imagefood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="fill_parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Malls"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="3"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="App name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coupons"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Markets"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
Related
Please help me create layout like this screen:
Images position need to be like on the screen. All time images scaling or resize borders.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="3">
<view
class=".widget.AvatarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/view6"
android:gravity="center"
android:layout_weight="1"
android:layout_gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2">
<view
class=".widget.AvatarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/view"
android:gravity="center" />
<view
class=".widget.AvatarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/view11"
android:gravity="center" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<view
class=".widget.AvatarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/view5"
android:layout_weight="1"
android:gravity="center" />
<view
class=".widget.AvatarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/view8"
android:layout_weight="1"
android:gravity="center">
</view>
<view
class=".widget.AvatarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/view10"
android:layout_weight="1"
android:gravity="center">
</view>
</TableRow>
</TableLayout>
But images need not scaling and resizing!
I'm receive Please help, thanks!
Check this sample layout and you can customize this for your own
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<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:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I have a LinearLayout with weightSum 10 which has 2 child LinearLayout with layout_weight 4 and 6. It works fine when background is color or nothing. But the problem occurs when I set a background image. What can be the problem and solution?
Working code:
<?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="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4"
android:background="#color/Blue"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="6"
android:background="#color/new_back"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="99" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnCustomers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/customer" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chemist"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/order" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnItemStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/item_status" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Status"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="99" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/notification" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnAttendance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/attendance" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attendance"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnExpenceClaim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/expence_clain" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exp. Claim"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Problematic code:
<?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="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4"
android:background="#drawable/top_menu"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="6"
android:background="#color/new_back"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="99" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnCustomers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/customer" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chemist"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/order" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnItemStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/item_status" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Status"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="99" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/notification" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnAttendance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/attendance" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attendance"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnExpenceClaim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/expence_clain" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exp. Claim"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
You need to understand how weight works. Weight will assign remaining space after the measure has been passed. If your image is wrapping its contents and it uses all the space, the remaining unused space (none) will be distributed based on weights. You have to adjust your containers and read about Linear Layout weight.
<?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="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4"
android:background="#drawable/ic_launcher" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="6"
android:background="#000000"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="99" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnCustomers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chemist"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnItemStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Status"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="99" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnAttendance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attendance"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="33"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/idbtnExpenceClaim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exp. Claim"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Found the solution! The problem was with layout theme set in eclipse for that particular xml file. Theme was set to Theme.NoTitleBar in that xml file. I switched it to default AppTheme which is Theme.Light, now it works. :)
This is a common misunderstanding about layout_weight. Rather than divide the total space of parent view based on each item's weight, it is the Extra Space that is divided.
As the official document says about layout weight and I quote:
LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space is should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero.
In your case, set the layout_height to 0dp means wrap_content, since the image is large enough, it occupies almost all the space of the parent view, which leads to no Extra space to be divided based on layout_weight. Since the wrap_content for pure color is just 1dp, it works fine since there is enough extra space.
To sum up, if you want the layout_weight to work like you expected, each view should be less than its weight of parent view.
To fix it, just wrap the weight=4 view into a new LinearLayout with weight set to 4.
Below is my gridview layout which works fine and clicks. But when I change my layout it's not clicking any more. Tell me why I just change xml not code. Tell me what is wrong in my xml? Why gridView stopped clicking? is it because of layout weight?
I'm changing from this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/image2"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:padding="5dp"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/title2"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:textColor="#000" />
</LinearLayout>
To this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/image2"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_weight="1"
android:gravity="center_horizontal"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:orientation="vertical" >
<TextView
android:id="#+id/title2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical"
android:textColor="#000000" />
<TextView
android:id="#+id/title3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical" >
<Button
android:id="#+id/ButtonSendFeedback"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/roundshapebtn"
android:text="Order Now"
android:textColor="#ffffff"
android:textSize="15pt" />
</LinearLayout>
You have some spaces in your layout maybe your click events did not trigger becasue of this. Just use below layout and check if your problem is solved:
<?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="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/image2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#58FA58"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/title2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#DF013A" />
<TextView
android:id="#+id/title3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#2EFEF7" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/ButtonSendFeedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dummy"/>
</LinearLayout>
I am trying to build a complex listview item layout with all of the elements being the same dimensions for each listview item with the entire layout taking up the whole width of the screen. So far I have attempted doing this using a linearlayout and found that this is the wrong approach. I have then attempted using a relative layout however this has not worked for me so I hope that someone can point out how I can make this work.
Here is a diagram of what I am trying to build.
Here is some more details about the diagram:
Only elements 5 and 6 have the same content for every list item. The
rest of elements all will have different text however the layout
should always be the same size.
Element 4 should only be 2 lines. Elements 1, 2 and 3 should only be 1
line.
Element 2 should be aligned left and element 3 should be aligned
right.
Element 2 and 3 should each be half of the width of element 4.
Here is my attempt at this layout using a RelativeLayout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="2dp">
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="20dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="#id/txtRaceNumber"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toRightOf="#id/txtRaceNumber" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txtRaceClass" />
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:paddingRight="8dip"
android:focusable="false"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txtRaceStartTime" />
<ImageView
android:src="#drawable/go"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/btnTracklist" />
</RelativeLayout>
Using this RelativeLayout all of the elements appear scrambled within the layout.
How can I get all of these elements to align as I have shown in the Diagram?
Is this what you need?
<LinearLayout
android:id="#+id/lin1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:text="TExt1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/lin1"
android:layout_toLeftOf="#+id/lin3">
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text4"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="text2"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="text3"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lin3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:focusable="false"
android:paddingRight="8dip" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:src="#drawable/ic_launcher" />
</LinearLayout>
try this code
<?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="90dp"
android:gravity="center|left"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left|center"
android:layout_gravity="center"
android:gravity="center"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<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:gravity="center"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left|center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<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:gravity="left|center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<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:gravity="left|center" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
</LinearLayout>
I have managed to get the desired layout using weightSum on the main layout.
Here is the code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/twolinechecked"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:maxHeight="?android:attr/listPreferredItemHeight"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:orientation="horizontal"
android:weightSum="1"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_gravity="center"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="6dip">
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/linearTextInner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal">
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:maxLines="1"
android:layout_alignParentRight="true"
android:gravity="right" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_marginLeft="5dip"
android:paddingRight="8dip"
android:layout_gravity="center_vertical|center_horizontal" />
<ImageView
android:src="#drawable/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignParentRight="true" />
</LinearLayout>
Follow below structure I feel you can achieve what you want use weight and weightSum.
<LinearLayout orientation="horizontal">
<LinearLayout>
<TextView/>
</LinearLayout>
<LinearLayout orientation="vertical">
<TextView/>
<LinearLayout orientation="horizontal">
<TextView/>
<TextView/>
</LinearLayout>
<ImageButton/>
<ImageView/>
</LinearLayout>
EDIT
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="2dp"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.2" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.7"
android:gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.3"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center" />
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15" />
<ImageButton
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15" />
</LinearLayout>
I have a layout problem, the idea is that the buttons and text dont show
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#5094c5"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingTop="8dp" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Set the height and width in the xml layout file to what they should be when they are visible but initially, in code, get a reference to them and make them invisible. Then, when needed, you can make them visible (in code).
Maybe better try with RelativeLayout. This seems to be too nested and too much complicated than it suppose to be.
You can give setVisibility() property to button and textview in layout.