I have a Relative Layout Containing following Views and Nested Relative Layouts. For Some devices there is a blank space left at the bottom of the screen. I want to equitably distribute the space to the nested views and viewgroups() to fill the Screen.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#color/tdmubiobgd"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MasterActivity$DummySectionFragment" >
<Button
android:id="#+id/ScanButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Scan" />
<ImageView
android:id="#+id/scan_adsView"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_alignLeft="#id/ScanButton"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="#drawable/ads" />
<RelativeLayout
android:id="#+id/scan_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/scan_adsView"
android:layout_below="#id/scan_adsView"
android:layout_marginTop="10px"
android:orientation="horizontal" >
<ImageView
android:id="#+id/Scan_Image"
android:layout_width="72px"
android:layout_height="72px"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/Scan_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/Scan_Image"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="#+id/Scan_DName"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView3"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:gravity="right"
android:text="DName "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
<TextView
android:id="#+id/Scan_Sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Scan_Name"
android:layout_toRightOf="#+id/Scan_Age"
android:text="Male"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Scan_Age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/Scan_Sex"
android:layout_alignBottom="#+id/Scan_Sex"
android:layout_alignLeft="#+id/Scan_Name"
android:text="30"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
<ImageView
android:id="#+id/scan_level1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/scan_header"
android:layout_below="#+id/scan_header"
android:scaleType="fitXY"
android:src="#drawable/l1warning" />
<RelativeLayout
android:id="#+id/scan_master"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/scan_level"
android:layout_below="#id/scan_level1"
android:layout_marginTop="10px"
android:orientation="horizontal" >
<TextView
android:id="#+id/scan_mname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MinionRush"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/scan_mdetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/scan_mname"
android:layout_below="#+id/scan_mname"
android:text="DoodlePlay"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/scan_period"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/scan_mdetails"
android:text="DartRace"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="#+id/scan_alarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:src="#drawable/alarm" />
</RelativeLayout>
<ImageView
android:id="#+id/scan_level2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/scan_master"
android:layout_below="#id/scan_master"
android:scaleType="fitXY"
android:layout_marginTop="10px"
android:src="#drawable/toempty" />
<Gallery
android:id="#+id/scan_gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scan_level2"
android:layout_marginTop="10px"
android:layout_alignParentLeft="true" />
<ImageView
android:id="#+id/faq"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scan_gallery"
android:layout_centerHorizontal="true"
android:layout_marginTop="10px"
android:scaleType="fitXY"
android:src="#drawable/faq" />
</RelativeLayout>
Use the following :
<?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:background="#ffffff">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#556677">
</RelativeLayout>
<Gallery
android:id="#+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#664411"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#997766">
</RelativeLayout>
</LinearLayout>
Hope this will help you....
use linear layout as your parent layout and give weights to all layouts.
Here is a XML for your question
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
<Gallery
android:id="#+id/gallery1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
use
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
orientation="vertical">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</RelativeLayout>
<Gallery
android:id="#+id/gallery1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</RelativeLayout>
</LinearLayout>
use linear layout and add
android:layout:weight="1"
in every tag..
if you want to use the Relative layout then,it is better that you should get the screen dimension and divide it into four, if you have four views
Refer this link for getting screen size
Related
I just want to use multiple layout in a single xml file.I have attached my code below. In that there will be an absolute layout that should be under Horizontal scroll. As a beginner I don't know how to implement it
need your help friends..
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/aagr_background2"
android:orientation="vertical" >
<fragment
android:id="#+id/adview153613"
android:name="com.sentientit.theiWedplanner.Fragadmob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/aanavigationbar" >
<Button
android:id="#+id/back"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:layout_marginTop="3dp"
android:layout_x="8px"
android:layout_y="3px"
android:background="#drawable/custom_btn_breaker_bay"
android:text="Back"
android:textColor="#ffffff"
android:textSize="20sp" />
<Button
android:id="#+id/home"
android:layout_width="50px"
android:layout_height="30px"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/back"
android:layout_marginRight="46dp"
android:background="#drawable/home1"
android:paddingBottom="12px"
android:paddingTop="10px"
android:visibility="gone" />
</RelativeLayout>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="61dp" >
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="61dp"
android:layout_x="120dp"
android:layout_y="35dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="38dp"
android:layout_y="30dp"
android:text="- Kid Seated"
android:textColor="#000000"
android:textSize="13dp"
android:typeface="serif" >
</TextView>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="6dp"
android:layout_y="28dp"
android:src="#drawable/kid" >
</ImageView>
</AbsoluteLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="437dp"
android:layout_y="3dp"
android:src="#drawable/add11_table" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="48dp"
android:layout_y="4dp"
android:text="Line"
android:textSize="20sp" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="128dp"
android:layout_y="4dp"
android:text="circle"
android:textSize="20sp" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="212dp"
android:layout_y="6dp"
android:text="vshape"
android:textSize="20sp" />
</AbsoluteLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
Thank you in advance
Not sure whether your looking for this alignment but i just gave a shot..... whenever you wish to fix layout at the bottom of screen make sure you use weight property i.e if you want fix button at the bottom of screen then put android:layout_height = "0dp" and layout_weight="1" for other major layout in the xml and to button which has to be fixed at the bottom use android:layout_height="wrap_content" and layout_weight = "0" that's all is the trick (sorry if i have made it hard to understand... just simply saying play with weight and height property)
<?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="#fff"
android:orientation="vertical" >
<fragment
android:id="#+id/adview153613"
android:name="com.sentientit.theiWedplanner.Fragadmob"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/back"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:layout_marginTop="3dp"
android:layout_x="8px"
android:layout_y="3px"
android:text="Back"
android:textColor="#ffffff"
android:textSize="20sp" />
<Button
android:id="#+id/home"
android:layout_width="50px"
android:layout_height="30px"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/back"
android:layout_marginRight="46dp"
android:paddingBottom="12px"
android:paddingTop="10px"
android:visibility="gone" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" >
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="61dp"
android:layout_x="120dp"
android:layout_y="35dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="38dp"
android:layout_y="30dp"
android:text="- Kid Seated"
android:textColor="#000000"
android:textSize="13dp"
android:typeface="serif" >
</TextView>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="6dp"
android:layout_y="28dp" >
</ImageView>
</AbsoluteLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="437dp"
android:layout_y="3dp" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="48dp"
android:layout_y="4dp"
android:text="Line"
android:textSize="20sp" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="128dp"
android:layout_y="4dp"
android:text="circle"
android:textSize="20sp" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="212dp"
android:layout_y="6dp"
android:text="vshape"
android:textSize="20sp" />
</AbsoluteLayout>
</LinearLayout>
Yes, you can use use multiple layouts in single XML using the <include>.
Here is a example for that:
<?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:background="#color/app_background"
android:orientation="vertical" >
<include layout="#layout/actionbar_main" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/img_rest_pic"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight=".35"
android:src="#drawable/upload_image" />
</LinearLayout>
</LinearLayout>
The actionbar_main.xml file is in different XML:
<?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="?android:attr/actionBarSize"
android:background="#drawable/navbar_txt"
android:orientation="vertical" >
<ImageButton
android:id="#+id/ibtn_action_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#null"
android:src="#drawable/navbar_back" />
<ImageButton
android:id="#+id/ibtn_action_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/ibtn_action_back"
android:layout_marginRight="5dp"
android:background="#null"
android:src="#drawable/nacbar_setting" />
<View
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#color/white" />
</RelativeLayout>
I'm trying to emulate a dock for a launcher with 3 text views evenly spaced out across said dock... For some reason I can't get my text views to center align with in there parent linear layouts, can someone please explain to me what is my issue here?
Here is my layout in XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF" >
<LinearLayout
android:id="#+id/footer"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99000000"
android:paddingBottom="20dp"
android:paddingTop="20dp" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/launcher_footer_icon"
android:gravity="center"
android:text="Internet Browser"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/launcher_footer_icon"
android:gravity="center"
android:text="Flight Tracker"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/launcher_footer_icon"
android:gravity="center"
android:text="Airline Info"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Try this out, I think you have too many inner layouts.. you can use layout_weight to achieve this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/blue"
android:orientation="horizontal"
android:padding="20dp"
android:weightSum="15.0" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5.0" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:gravity="center"
android:text="Internet Browser"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5.0" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:gravity="center"
android:text="Flight Tracker"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5.0" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:gravity="center"
android:text="Airline Info"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
I cant seem to properly position my layouts the way I want them to be.
What my layout looks like is like this:
LinearLayout
LinearLayout
ListView
LinearLayout
TextView
TextView
TextView
Button
My aim is to have it like this:
Any thoughts on this please as to what Layouts i will use?
Help will be appreciated
try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/homeTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:background="#android:color/holo_blue_dark"
>
<!-- arrange your lables and button here -->
</LinearLayout>
<LinearLayout
android:layout_width="100dip"
android:layout_height="fill_parent"
android:background="#android:color/holo_purple"
android:layout_marginLeft="20dip"
>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
></ListView>
</LinearLayout>
</RelativeLayout>
look the wireframe below . you can set corner-radius and add controls in it.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/layout2"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="100dip"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/layout1"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<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" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
You can use the Relative layout for this as follows
<?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" >
<RelativeLayout
android:id="#+id/first_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dip" >
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn1" />
<Button
android:id="#+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn2" />
<Button
android:id="#+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn3" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/second_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="#+id/first_layout" >
<GridView
android:id="#+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</GridView>
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
</RelativeLayout>
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.
I've got a view with a SlidingDrawer at the bottom. When I open it, it does not open entirely and stops at previous sibling view.
Anybody can help?
Thanks
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:id="#+id/top_bar"
android:layout_width="fill_parent" android:layout_height="44dp"
android:background="#drawable/top_bar">
<ImageView android:id="#+id/btn_popup"
android:layout_width="20dp" android:layout_height="20dp"
android:background="#456463" android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp" />
</RelativeLayout>
<LinearLayout android:id="#+id/featured"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="50dp" android:background="#drawable/bg_goodidea">
<TextView android:id="#+id/featured_title"
android:layout_width="280dp" android:layout_height="wrap_content" />
<TextView android:id="#+id/featured_txt"
android:layout_width="280dp" android:layout_height="wrap_content" />
</LinearLayout>
<ViewStub android:id="#+id/menu_container"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</ViewStub>
<SlidingDrawer android:id="#+id/banner"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:handle="#+id/handle" android:content="#+id/content">
<TextView android:id="#id/handle" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#drawable/bg_banner_title"
android:text="banner title" android:paddingLeft="50dp"
android:gravity="center_vertical" />
<ImageView android:id="#id/content"
android:layout_width="fill_parent" android:layout_height="100dp"
android:background="#286427" />
</SlidingDrawer>
</LinearLayout>
Layout inflated in the ViewStub:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu_cat_0" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="100dp"
android:layout_marginTop="10dp">
<LinearLayout android:id="#+id/cat_2" android:tag="2"
android:orientation="vertical" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="1"
android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/ic_cat_2" />
<TextView android:text="#string/cat_communes"
style="#style/IconTitle" />
</LinearLayout>
<LinearLayout android:id="#+id/cat_4" android:tag="4"
android:orientation="vertical" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="1"
android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/ic_cat_4" />
<TextView android:text="#string/cat_hebergements"
style="#style/IconTitle" />
</LinearLayout>
<LinearLayout android:id="#+id/cat_3" android:tag="3"
android:orientation="vertical" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="1"
android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/ic_cat_3_vide" />
<TextView android:text="#string/cat_agenda" style="#style/IconTitle" />
</LinearLayout>
<LinearLayout android:id="#+id/cat_10" android:tag="10"
android:orientation="vertical" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="1"
android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/ic_cat_10" />
<TextView android:text="#string/cat_meteo" style="#style/IconTitle" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Don't put it in a LinearLayout. Put it in a RelativeLayout, so it can float over top of earlier children.