I want to create a menu with 6 buttons that is suppose to be in this layout. Can anyone help me please?
This will give you that exact layout (I used ImageButtons in this layout)
I added the scroll view so that the menu will scroll on very small screens. You can remove that if you want.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" >
<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:layout_weight="1"
android:weightSum="2" >
<ImageButton
android:id="#+id/id1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
<ImageButton
android:id="#+id/id2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<ImageButton
android:id="#+id/id3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
<ImageButton
android:id="#+id/id4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<ImageButton
android:id="#+id/id5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
<ImageButton
android:id="#+id/id6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Or you can just use a TableLayout
you can use <TableLayout> ... </TableLayout>
example: http://www.mkyong.com/android/android-tablelayout-example/
Related
I have posted my code below when ever I try to use nestedsroll view the screen dosen't scroll and when i add "android:nestedScrollingEnabled="true"" inside my nestedscrollview the app crashes I dont know why is this happening I am using grid view inside the nested scroll view can somebody help me with this it would be of great use , Thank You
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/wheel"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:layout_marginTop="20dp"
android:layout_marginEnd="100dp"
android:src="#drawable/mywheel" />
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/wheel"
android:layout_marginTop="10dp"
android:numColumns="5"
android:layout_marginStart="90dp"
android:layout_marginEnd="90dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/seat_info"
android:layout_below="#+id/grid"
android:layout_height="40dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:weightSum="3"
android:layout_marginEnd="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_open"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:text="Available"
android:paddingStart="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="3"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_booked"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="2.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:text="Unavailable"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_selected"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:paddingStart="5dp"
android:gravity="center_vertical"
android:text="Selected"/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/seat_info"
android:paddingBottom="10dp">
<Button
android:id="#+id/bt_booking_details"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/circular_button"
android:fontFamily="#font/montserrat_regular"
android:text="Enter Booking Details"
android:layout_marginBottom="10dp"
android:layout_alignParentBottom="true"
android:textColor="#android:color/white"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:textSize="17dp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
GridView already has scrolling built in, so it conflicts with a NestedScrollView. You should be using a RecyclerView with a GridLayoutManager and appbar_scrolling_view_behavior layout behavior in place of the NestedScrollView.
my Internal Linear Layout (with blue background) seems to have some margin at bottom with white space, do not know how to remove this.
The External Linear layout also have no padding or margin , from where this whitespace came
[![<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#E78F23">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:clickable="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:onClick="dashboard"
android:src="#drawable/menu"/>
<TextView
android:id="#+id/ticket_reciever_header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textColor="#ffffff"
android:text="Mike Smith"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#20000000"
android:layout_alignParentBottom="true">
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="35%0FF"
android:gravity="center_vertical"
android:layout_marginTop="55dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="35dp"
android:textSize="40sp"
android:textColor="#color/background_material_dark"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/layer"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="horizontal"
android:background="#91A4AB"
android:weightSum="3">
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="55dp">
<TextView
android:id="#+id/product_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="AMG 020 ladies shirt"
android:layout_marginTop="6dp"
android:layout_marginLeft="12dp"
android:textSize="20sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/product_name"
android:text="Purple heather"
android:layout_marginLeft="12dp"
android:textSize="12sp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:clickable="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_alignParentRight="true"
android:src="#drawable/share_upper"/>
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/qr_code"
android:layout_marginTop="30dp"
android:layout_gravity="center"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#3E41B2"
>
<ImageButton
android:id="#+id/shedule"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/tecket_recieved_shedule"
android:layout_weight="1"
android:background="#00000000"/>
<ImageButton
android:id="#+id/location"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ticket_received_location"
android:background="#00000000"/>
<ImageButton
android:id="#+id/favourite"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/favourite"
android:layout_weight="1"
android:background="#00000000"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/share"
android:layout_weight="1"
android:background="#00000000"/>
</LinearLayout>
</LinearLayout>]
1]1
Just update your last Linear Layout Height . Set match_parent instead Hard-Coded 50dp .
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#3E41B2"
>
<ImageButton
android:id="#+id/shedule"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/tecket_recieved_shedule"
android:layout_weight="1"
android:background="#00000000"/>
<ImageButton
android:id="#+id/location"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ticket_received_location"
android:background="#00000000"/>
<ImageButton
android:id="#+id/favourite"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/favourite"
android:layout_weight="1"
android:background="#00000000"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/share"
android:layout_weight="1"
android:background="#00000000"/>
</LinearLayout>
try
android:layout_height="match_parent"
instead of
android:layout_height="50dp"
in your last LinearLayout.
hope this helps!
You have set the height of the layout as a fixed value (50dp). Change it so it takes all available space changing
android:layout_height="50dp"
for
android:layout_height="match_parent"
For future ui issues like this you can enable "Show layout bounds" in Developer Options. It will show the size of every view in the screen
I have Linearlayout that have have multiple linear layouts in which one of the main layout have a LinearLayout and Listview. LinearLayout contains multiple ImageView and TextView now I want to add ScrollView on this LinearLayout. But if I am adding the ScrollView my ListView got hidden and onClick of the ImageView I want to highlight that LinearLayout.
My XML is :
<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:id ="#+id/mainFilterLayout"
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:id="#+id/companyLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_gravity="left"
android:adjustViewBounds="true"
android:background="#mipmap/ic_launcher" />
<View
android:clickable="true"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Clear" />
<Button
android:id="#+id/btnApply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
//**I want to add scroll view on this linear layout**
<LinearLayout
android:id="#+id/categoryLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical">
<LinearLayout
android:id="#+id/brandLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
//**Here on click of imageviwew i want set as selected for this linear layout**
<ImageView
android:id="#+id/mobbrand"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtBrand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Brand" />
</LinearLayout>
<LinearLayout
android:id="#+id/colorLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobColor"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="COLOUR" />
</LinearLayout>
<LinearLayout
android:id="#+id/sizeLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobSize"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Size" />
</LinearLayout>
<LinearLayout
android:id="#+id/offerLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobOffers"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txtPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Price" />
</LinearLayout>
<LinearLayout
android:id="#+id/othersLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobother"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txtOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="OTHER" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="#+id/subCategory"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:cacheColorHint="#android:color/transparent"
android:divider="#fff"
android:dividerHeight="1dp"
android:fadingEdge="none">
</ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I hope this will work for u :
<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:id ="#+id/mainFilterLayout"
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:id="#+id/companyLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_gravity="left"
android:adjustViewBounds="true"
android:background="#mipmap/ic_launcher" />
<View
android:clickable="true"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Clear" />
<Button
android:id="#+id/btnApply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical">
<LinearLayout
android:id="#+id/brandLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobbrand"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtBrand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Brand" />
</LinearLayout>
<LinearLayout
android:id="#+id/colorLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobColor"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="COLOUR" />
</LinearLayout>
<LinearLayout
android:id="#+id/sizeLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobSize"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Size" />
</LinearLayout>
<LinearLayout
android:id="#+id/offerLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobOffers"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txtPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Price" />
</LinearLayout>
<LinearLayout
android:id="#+id/othersLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobother"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txtOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="OTHER" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ListView
android:id="#+id/subCategory"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:cacheColorHint="#android:color/transparent"
android:divider="#fff"
android:dividerHeight="1dp"
android:fadingEdge="none">
</ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Simply do one thing cut the amount of code that you want in scrollview.... Now add scrollview in place of the code that u just "cut" ... now scrollview also have a child layout as linear layout.... in that linear layout make height to be wrap_content..... next place your code inside that linear layout... ListView outside the scrollayout...
[code]--------- Ctrl+X
replace with
<ScrollView>
<LinearLayout>
[code]-------- Ctrl+V
enter code here
</LinearLayout>
</ScrollView>
<ListView> -------- here add listview
I'm trying to design the layout for tablet. I want each control to have equal spaces between each other. How all of these can be aligned properly ? Sorry I cannot attach the image as I don't have 10 reputation :(. Please help
Here is the layout code and the parent layout is linear layout.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="125dp"
android:background="#517398"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="125dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="30dp"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/image_agenda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.0"
android:src="#drawable/agenda_view" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="125dp"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginRight="40dp"
android:background="#000000" />
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:src="#drawable/month_view" />
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="40dp"
android:background="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="125dp"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/image_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
android:src="#drawable/day_view" />
</LinearLayout>
</RelativeLayout>
// try this way,hope this will help you...
<?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:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="125dp">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center">
<ImageButton
android:id="#+id/image_agenda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center">
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center">
<ImageButton
android:id="#+id/image_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Please check the below Sample layout code i have made to test
i dont know for what purpose you are using and how you are using the center element 2 textview so right now i have commented that if you want that center element all 2 textview and imagebutton with equal space distribution then same formula layout_weight you use that i have used for this code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/image_agenda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<!-- <TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginRight="40dp"
android:background="#000000" /> -->
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<!-- <TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#000000" /> -->
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/image_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
if you have any doubt you can ask me.....
try Using Weight Attribute and Avoid Using Relative Layout. Define WeightSum to parent Layout and weight to childs. It will work for both Tablet and Phones[portrait]
If u are trying to divide spaces acc. to width then give width = 0dp to childs and if Acc to height then give height 0dp to childs when using weights.
code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="125dp"
android:background="#517398"
android:weightSum="9" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_marginBottom="8dp"
android:paddingLeft="30dp"
android:layout_weight="3"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/image_agenda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.0"
android:src="#drawable/agenda_view" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_centerHorizontal="true"
android:layout_weight="3"
android:orientation="horizontal" >
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginRight="40dp"
android:background="#000000" />
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:src="#drawable/month_view" />
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="40dp"
android:background="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_alignParentRight="true"
android:layout_weight="3"
android:orientation="horizontal"
android:paddingRight="30dp" >
<ImageButton
android:id="#+id/image_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
android:src="#drawable/day_view" />
</LinearLayout>
</LinearLayout>
Note: Relative Layout do not support weight or WeightSum.
Hi
I have designed a layout, i have attached a screen shot of it. I was getting an unwanted space between linear layout(tabsFragmentll) and grid view linear layout, so to remove the space i added a tag in linear layout grid view as android:layout_marginTop= "-10dp".
After adding the tag, it removed the space between the linear layout(tabsFragmentll) and grid view linear layout, but at the bottom of the screen i am getting an unwanted space which is shown at the bottom of the screen.
I am trying hard to remove the unwanted spaces, but am not able to do so. Please look in to it and give me your suggestions.
The following is my layout design code:
<LinearLayout
android:id="#+id/slide_show_content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.7" >
<FrameLayout
android:id="#+id/slide_show_fragment_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/tabsFragmentll"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1" >
<fragment
android:name="com.beverly.fragments.TabsButtonFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginTop="-10dp"
android:layout_weight="1.15"
android:baselineAligned="false" >
<RelativeLayout
android:id="#+id/center_pane_rl"
android:layout_width="200dp"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/center_pane_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="#+id/places_list_view_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/tab_fragment_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
<TableRow
android:id="#+id/tableRowBtns"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#drawable/toolbar_background" >
<FrameLayout
android:id="#+id/checkinframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/checkInIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/checkin" />
<TextView
android:id="#+id/checkInTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/checkin"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/cameraframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/cameraIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/camera" />
<TextView
android:id="#+id/cameraTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/camera"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/photosframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/photosIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/photos" />
<TextView
android:id="#+id/photosTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/photos"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/termsframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/termsIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/terms" />
<TextView
android:id="#+id/termsTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/terms"
android:textSize="14sp" />
</FrameLayout>
</TableRow>