I use tablelayout instead of the custom header title bar
Now my layout like the xml I show below, and I want to put the 2 icon and the text align right, but when I use android:layout_gravity="right" it seems not work, so how can I do it ?
This is my layout xml:
< ? 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" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#4494D1" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="简易尺子"
android:textColor="#fff"
android:textSize="25dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="#drawable/android2"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="关于"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="#drawable/programs"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="帮助"
android:textColor="#fff" />
</LinearLayout>
</TableRow>
</TableLayout>
<SurfaceView
android:layout_width="match_parent"
android:id="#+id/surfaceView1"
android:layout_height="match_parent">
</SurfaceView>
</LinearLayout>
The layout gravity you set is not to affect the positioning of the TextView and the ImageView in the TableRow, rather it will position them in the wrapping LinearLayout which is not quite what you need. I suggest you define the following attribute to your TableLayout:
<TableLayout
android:layout_width="fill_parent"
android:layout_width="wrap_content"
android:stretchColumns="0,1">
This will make the first two columns of the raw expand and thus shrink the rightmost column to the right.
NOTE (IMPORTANT) Currently you do not have a valid layout defined: you have a TableRow in LinearLayout - this is not allowed - you should place the row in TableLayout like the one I have defined.
try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="#+id/textView2"
android:text="简易尺子"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/imageButton2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageButton1"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/text2"
android:text="关于"
android:textColor="#fff" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/imageButton2"
android:text="帮助"
android:textColor="#fff" />
</RelativeLayout>
</TableRow>
</TableLayout>
<SurfaceView
android:id="#+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/tableLayout1" >
</SurfaceView>
</RelativeLayout>
Related
I am working with android layout.I have two table in my layout and i have put those table in scrollview.But currently the problem that i faced is that the whole layout is not displayed in the small screen android phone.I want the layout in scrollview but as i have googled it for that,I have found that i can not put these much contents(textviews,table layout) vertical scrollview. Is there any other way for displaying all the contents in the small screen mobile phone? Thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView2"
android:background="#drawable/back1"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Name Label -->
<!-- Input Name -->
<!-- Input Name -->
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:layout_marginTop="2dp"
android:text=""
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:text=""
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:text=""
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView5"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text=""
android:textColor="#FFFFFF" />
<TableLayout
android:id="#+id/maintable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp" >
</TableLayout>
<TableLayout
android:id="#+id/maintable1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" >
</TableLayout>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/list"
android:text=""
android:textColor="#FFFFFF" />
<ListView
android:id="#android:id/list"
style=" android:listViewStyle"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="#+id/textView6"
android:layout_marginLeft="33dp"
android:drawSelectorOnTop="true"
android:textColor="#FFFFFF" >
</ListView>
</LinearLayout>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_gravity="bottom"
android:text="ff"
android:layout_marginBottom="5dp"
android:textColor="#FFFFFF"
android:textColorLink="#FFFFFF" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="5dp"
android:text="fv"
android:layout_gravity="bottom"
android:textColor="#FFFFFF"
android:textColorLink="#FFFFFF" />
</LinearLayout>
You cannot have two ScrollViews on one screen. The scrolling could get very strange for your users. there is no cursor, so you can't just
To solve this, you can put everything into a scrollview like this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="145dp"
android:layout_below="#+id/textView2"
android:background="#drawable/back1"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:layout_marginTop="2dp"
android:text=""
android:textColor="#FFFFFF" />
...
<TableLayout
android:id="#+id/maintable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp" >
</TableLayout>
<TableLayout
android:id="#+id/maintable1"
android:layout_width="283dp"
android:layout_height="500dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" >
</TableLayout>
...
</LinearLayout>
</ScrollView>
Or just put the two tables into a scrollview. If you do this, though, the contents of the tables may scroll off the screen and not be visible ever. You can use weighted layouts if you think the content will display well, but it probably won't. If you want to try, do it like this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="145dp"
android:layout_below="#+id/textView2"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/maintable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp" >
</TableLayout>
<TableLayout
android:id="#+id/maintable1"
android:layout_width="283dp"
android:layout_height="500dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" >
</TableLayout>
</LinearLayout>
</ScrollView>
I have a layout with a view text views, a table and then some buttons at the bottom.
I wanted the buttons to always be at the bottom regardless of the height of the table so I changed the layout to relative so I could do this.
However this mashed all the textviews and the table into one line. So I put these in a LinearLayout within the RelativeLayout which I thought would fix the problem. Problem now is that only the first TextView and the buttons at the bottom show up. Everything else is missing.
Here is the xml code I am using to define this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="4dip"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/view_meal_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Spaghetti Bolognaise"
android:textSize="25sp" />
<TextView
android:id="#+id/view_meal_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dinner"
android:textSize="16sp" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/view_day_calories"
android:text="#string/calories_label"
android:textSize="18sp" />
<TextView
android:id="#+id/view_day_calories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/calories_today_value"
android:textSize="18sp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="10dip"
android:background="#color/hr" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:stretchColumns="0,1,2" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/meal_table_ingred_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ingredient"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/meal_table_quantity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/quantity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/meal_table_calories_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/calories"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1.0" >
<Button
android:id="#+id/edit_meal_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/edit_meal_label" />
<Button
android:id="#+id/favourite_meal_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/favourite_meal_label" />
</LinearLayout>
</RelativeLayout>
Thanks for your help!
Change
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
to
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
I have a relative layout with two linear layout inside it with two textviews in each of them.
I wanted the textviews to appear horizontally as a row.
The code is given below:
<RelativeLayout
android:id="#+id/linear2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/txtlinear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/esms_parentfees_classdetais"
android:orientation="horizontal" >
<TextView
android:id="#+id/esms_parentfees_datetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/esms_parentfees_datedetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Notes on your XML:
You can't use toRightOf, etc, within a LinearLayout
RelativeLayout's don't have an orientation
This is needed for some reason to show all the XML? Ignore this line
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/esms_parentfees_datetext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<TextView
android:id="#+id/esms_parentfees_datedetais"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
</LinearLayout>
</RelativeLayout>
The easiest way would be to make the outer RelativeLayout a LinearLayout
<LinearLayout
android:id="#+id/linear2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
Then remove any tag like
android:layout_toRightOf="#+id/esms_parentfees_classdetais"
Or, you could just change the tag mentioned above to
android:layout_below="#+id/esms_parentfees_classdetais"
if you need the four textviews in a row its easy to just use a linear layout with the four text views in it (or a table layout) instead of using two linear layouts in a relative layout.
Have a look at this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtlinear"
>
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_datetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_datedetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
</LinearLayout>
or
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtlinear"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_datetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_datedetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
</TableRow>
</TableLayout>
or if its a compulsion that you need a relative layout with two linear layouts in it you can follow any of the solutions above
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/esms_parentfees_classtext"
/>
</RelativeLayout>
Only the first nested linear layout is showing up, any idea why? The first textView inside the 2nd linear layout shows up, and the layout is the proper height, but none if it's contents can be viewed.
<?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:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="42dp"
android:background="#FAFA25"
android:height="200dp"
android:text="#string/hello"
android:textColor="#222222"
android:textSize="20dp" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/width" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" >
<requestFocus />
</EditText>
</LinearLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="#string/totalWidth"
android:layout_marginRight="10dp" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_height="wrap_content"
android:background="#999999"
android:layout_width="fill_parent"
android:layout_margin="10dp"
android:padding="4dp"
android:weightSum="100" >
<TextView
android:id="#+id/textView5"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="#string/numOne"
android:layout_weight="62"
android:background="#ffffff"
android:gravity="center"
android:textColor="#222222"
android:layout_marginRight="1dp" />
<TextView
android:id="#+id/textView6"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="#string/numTwo"
android:background="#ffffff"
android:layout_weight="38"
android:gravity="center"
android:textColor="#222222"
/>
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Calculate" />
</LinearLayout>
</LinearLayout>
linearLayout3 , orientation is horizontal, in case you are wondering why, default orientation is horizontal. and since textView has layout_width="fill_parent", the next child will not show up.
change the orientation to vertical.
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.