I'm trying to make two identical buttons with the same height, but when the text is too long (the second button) then breaks markup. How can I fix it?
xml layout:
<?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">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:text="test"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"/>
<Button
android:padding="0dp"
android:text="Arterial tension disturbance"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Add android:singleLine="true"
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:singleLine="true"
android:text="test"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"/>
<Button
android:singleLine="true"
android:padding="0dp"
android:text="Arterial tension disturbance"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"/>
</LinearLayout>
use wrap_content instead of 0dp
<Button
android:padding="0dp"
android:text="Arterial tension disturbance"
android:layout_height="100dp"
android:layout_width="wrap_content"
android:layout_weight="1"/>
You can try this: (Edited)
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100" >
<Button
android:layout_width="fill_parent"
android:text="yourText"
android:layout_height="wrap_content"
android:layout_weight="50" />
<Button
android:layout_width="fill_parent"
android:text="yourText"
android:layout_height="wrap_content"
android:layout_weight="50" />
Related
Trying to align button at Bottom using LinearLayout, but getting just below TextView.
To set button at bottom, I am using android:layout_gravity="bottom" but still not done
LinearLayout xml
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_gravity="bottom"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Bottom" />
</LinearLayout>
</LinearLayout>
Change second linear layout to
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
This will put the button at the bottom and this layout will take the rest of the space
Yoy have to use like this....
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Bottom" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_gravity="bottom"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Bottom" />
</LinearLayout>
</LinearLayout>
I could not use the suggested answer as I had multiples of 3 vertical ones (each with specific weights) inside a horizontal one. So, ended up using margin top for specific button/widget instead. Working fine so far.
Did not want to change to RelativeLayout as that meant many changes in this scenario.
I'm trying to get TextView to wrap according to the device screensize so that the 3 button at the bottom will always be visible at the bottom of screen.
The layout I'm trying to get
I've tried the solution from here but the ScrollView doesn't seem to work. The 3 buttons is not visible.
The bad layout I'm getting :(
Here are my code. Thanks for reading.
<?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">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true">
<TextView
android:text="#string/default_tnc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
this is what you need , just copy and paste
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_above="#+id/ll_layout"
android:padding="10dp"
android:layout_weight=".8">
<TextView
android:text="#string/temp_txt"
android:textColor="#android:color/black"
android:background="#android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
/>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/ll_layout"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_weight="1"
android:text="Button 1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_weight="1"
android:text="Button 2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dp"
android:text="Button 3"/>
</LinearLayout>
</RelativeLayout>
Add android:layout_weight="1" to your ScrollView and change height of ScrollView to 0
Remove android:layout_weight="1" from your TextView
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
android:layout_weight="1.0"
android:fillViewport="true">
<TextView
android:text="#string/default_tnc"
android:layout_width="fill_parent"
android:layout_height="fill_parent" // or wrap_content
/>
</ScrollView>
Hope this help
You can RelativeLayout
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".lActivity">
<ScrollView
android:id="#+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
// enter code here
/>
</CrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="#FFFFFF">
<Button>
<Button>
<Button>
</RelativeLayout>
</RelativeLayout>
Instead of using a LinearLayout as the main parent, Just use a RelativeLayout. Then just use the layout_above attribute in the ScrollView to have it set to be above the .
ativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/id_rl_below"
android:layout_alignParentTop="true"
android:scrollbars="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:text="asdhgfahgdsashgaweatlweiutnwaueytluwae ytbluwae ytbluewzybltuewzsyb tzsydgzlu ybeutzybwlutvybwelutyvzewuiybtuwzey btuzwey tluiwg usdbugdslyuggjzsg zsdg sd mgzsdnzsntzsetxseyuxtrutfru xtfrunftu nxut uctr mxr untrxuxdumtrrumxrtmuxrumnrxtumn"
android:textSize="50dp" />
</ScrollView>
<LinearLayout
android:id="#id/id_rl_below"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3" />
</LinearLayout>
</RelativeLayout>
To know more about how to use RelativeLayouts. You can check the Official Android Developers Site -- RelativeLayout.LayoutParams. Hope this helps. :)
I've been trying to find a way to move my buttons to the bottom half in my xml file. Currently they are in the top half.
I am trying to follow this solution found here, but I am afraid that it is inapplicable.
Put buttons at bottom of screen with LinearLayout?
My buttons.xml is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TableLayout android:id="#+id/tableLayout1"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<Button
android:id="#+id/block_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_weight="0.09"
android:background="#ff5ac3ff"
android:drawableLeft="#drawable/ic_action"
android:gravity="center_horizontal|center_vertical"
android:text="#string/block_apps"
android:textSize="22sp" />
<Button
android:id="#+id/security_settings_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff5ac3ff"
style="?android:attr/borderlessButtonStyle"
android:layout_weight="0.09"
android:drawableLeft="#drawable/ic_settings"
android:gravity="center_horizontal|center_vertical"
android:text="#string/security_settings"
android:textSize="22sp"/>
<Button
android:id="#+id/blacklist_whitelist_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff5ac3ff"
style="?android:attr/borderlessButtonStyle"
android:drawableLeft="#drawable/ic_blacklist_red"
android:gravity="center_horizontal|center_vertical"
android:text="#string/blacklist_whitelist"
android:textSize="22sp"
android:layout_weight="0.09"/>
</LinearLayout>
You should try something like this. Basically, if you're using layout_weight, you need to set the height or width (depending or your orientation: vertical or horizontal) to "0dp". Otherwise, the view won't use the weight attribute. Try this xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="#+id/emptySpace"
android:layout_height="0dp"
android:layout_width="fill_parent"
android:layout_weight="3" />
<Button
android:id="#+id/block_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="right|center_vertical"
android:layout_weight="1"
android:background="#ff5ac3ff"
android:drawableLeft="#drawable/ic_action"
android:gravity="center_horizontal|center_vertical"
android:text="#string/block_apps"
android:textSize="22sp" />
<Button
android:id="#+id/security_settings_button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ff5ac3ff"
style="?android:attr/borderlessButtonStyle"
android:layout_weight="1"
android:drawableLeft="#drawable/ic_settings"
android:gravity="center_horizontal|center_vertical"
android:text="#string/security_settings"
android:textSize="22sp"/>
<Button
android:id="#+id/blacklist_whitelist_button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ff5ac3ff"
style="?android:attr/borderlessButtonStyle"
android:drawableLeft="#drawable/ic_blacklist_red"
android:gravity="center_horizontal|center_vertical"
android:text="#string/blacklist_whitelist"
android:textSize="22sp"
android:layout_weight="1"/>
</LinearLayout>
Btw, I changed your tablelayout to an empty textview, but you should be able to use any other type of view there. It's just there to fill up space.
Also, with layout_weights, be careful with layouts that extend beyond the screen size (like scrollview). That will throw off your weights. Layout weights are best suited for known layout dimensions.
I would suggest you to divide the whole layout into 6 equal LinearLayouts and then set the buttons in the last three layouts..
Try this code..
<LinearLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent"></LinearLayout>
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent"></LinearLayout>
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent"></LinearLayout>
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button
android:id="#+id/block_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_weight="0.09"
android:background="#ff5ac3ff"
android:drawableLeft="#drawable/ic_action"
android:gravity="center_horizontal|center_vertical"
android:text="#string/block_apps"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button
android:id="#+id/security_settings_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff5ac3ff"
style="?android:attr/borderlessButtonStyle"
android:layout_weight="0.09"
android:drawableLeft="#drawable/ic_settings"
android:gravity="center_horizontal|center_vertical"
android:text="#string/security_settings"
android:textSize="22sp"/>
</LinearLayout>
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button
android:id="#+id/blacklist_whitelist_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff5ac3ff"
style="?android:attr/borderlessButtonStyle"
android:drawableLeft="#drawable/ic_blacklist_red"
android:gravity="center_horizontal|center_vertical"
android:text="#string/blacklist_whitelist"
android:textSize="22sp"
android:layout_weight="0.09"/>
</LinearLayout>
</LinearLayout>
Please do tell me what the output is..
I've tested this, it should work, you'll have to change the button attributes since I was using test content & images.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TableLayout android:id="#+id/tableLayout1"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="vertical">
<Button
android:id="#+id/block_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff5ac3ff"
android:drawableLeft="#drawable/ic_launcher"
android:gravity="center_horizontal|center_vertical"
android:text="#string/block_apps"
android:textSize="22sp" />
<Button
android:id="#+id/security_settings_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff5ac3ff"
style="?android:attr/borderlessButtonStyle"
android:drawableLeft="#drawable/ic_launcher"
android:gravity="center_horizontal|center_vertical"
android:text="security settings"
android:textSize="22sp"/>
<Button
android:id="#+id/blacklist_whitelist_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff5ac3ff"
style="?android:attr/borderlessButtonStyle"
android:drawableLeft="#drawable/ic_launcher"
android:gravity="center_horizontal|center_vertical"
android:text="black white list"
android:textSize="22sp"/>
</LinearLayout>
</LinearLayout>
I'm new android. I have a little bit stack in designing layout for Android. In my scenario, I have two button with Linear Layout. Here my xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/isp_home_color"
>
<Button
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="1"
android:text="#string/sync_text"
android:background="#color/sync_text_color"
android:id="#+id/btn_syncpin"
android:layout_gravity="left"
android:textStyle="bold"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="70dp"
android:text="#string/topup_text"
android:background="#color/topup_text_color"
android:id="#+id/btn_topup"
android:layout_gravity="right"
android:textStyle="bold"/>
<!--Table Layout will come here -->
</LinearLayout>
Here image for this.
When I add new TableLayout inside Linear Layout. I got this.
Here my xml for Table Layout.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</TableLayout>
Actually, I don't want like this. I want two button as shown in first image. Then, next table layout will occur under this two button. Please help me how can I do this layout. Please pointing to me how to make this. Thanks with advanced.
Give orientation as vertical to the LinearLayout not the TableLayout.Put Two buttons in a LinearLayout with orizontal orientation and give orientation "vertical" for the parent LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#456789"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal">
<Button
android:id="#+id/btn_syncpin"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#123456"
android:text="tring/"
android:textStyle="bold" />
<Button
android:id="#+id/btn_topup"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_gravity="right"
android:layout_weight="1"
android:background="#978969"
android:text="topup_text"
android:textStyle="bold" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
</TableLayout>
</LinearLayout>
Check this out, I just checked it on my Machine and it works as desired, although the background preference and the display strings have been removed.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_syncpin"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="left"
android:layout_weight="1"
android:textStyle="bold" />
<Button
android:id="#+id/btn_topup"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="right"
android:layout_weight="1"
android:textStyle="bold" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/linearLayout2">
</TableLayout>
</RelativeLayout>
take Relative Layout as a parent layout.
Following is an example. it will display your buttons and table layout too
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/isp_home_color"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_syncpin"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#color/sync_text_color"
android:text="#string/sync_text"
android:textStyle="bold" />
<Button
android:id="#+id/btn_topup"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="right"
android:layout_weight="1"
android:background="#color/topup_text_color"
android:text="#string/topup_text"
android:textStyle="bold" />
</LinearLayout>
<TableLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/linearLayout2" >
</TableLayout>
</RelativeLayout>
thanks
This answer tells only implementation of button_bar_layout for all android versions with buttons at the bottom/top of an activity which look like AlertDialog with OK/Cancel buttons.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="?android:attr/listDivider"
android:orientation="vertical"
android:showDividers="middle" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:divider="?android:attr/listDivider"
android:dividerPadding="12dp"
android:orientation="horizontal"
android:showDividers="middle" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:drawable/list_selector_background"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="One" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:drawable/list_selector_background"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="Two" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
</TableLayout>
</LinearLayout>
Credits: Who else ? Johnkil
// try this way here i gave you alternative to achieve your requirement from give all of above
1. header.xml
<?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="wrap_content"
android:orientation="horizontal"
android:background="#color/isp_home_color">
<Button
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="1"
android:text="#string/sync_text"
android:background="#color/sync_text_color"
android:id="#+id/btn_syncpin"
android:textStyle="bold"/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="70dp"
android:text="#string/topup_text"
android:background="#color/topup_text_color"
android:id="#+id/btn_topup"
android:textStyle="bold"/>
</LinearLayout>
2.main.xml
<?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:padding="5dp"
android:orientation="vertical">
<include
layout="#layout/header"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="1">
</TableLayout>
</LinearLayout>
My popup window design left blank space on top of the window. i try different layout options but space persist.i don't understand how to eliminate this.i am using Custom popup Please help.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#FFF"
android:text="Input a Value"/>
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/severity_rating"
android:layout_marginRight="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/popup_et"
android:layout_height="wrap_content"
android:layout_width="100dp"
android:inputType="number" />
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Ok"/>
<Button
android:id="#+id/dialogButtonCancel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="cancel"/>
</LinearLayout>
</LinearLayout>
use dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Setting height to fill_parent to the first linear layout doesn't help ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
Try this..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
and your imageview give as src
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/severity_rating"
android:layout_marginRight="5dp" />
Use android:layout_weight="" for your linearlayout objects and arrange their appearance in window. Use especially for the item which will occupy more space.
Popup Window
for this view, I use
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/popborder_record"
android:orientation="vertical">
<TextView
android:id="#+id/tvCHLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_blue_grey_200"
android:text="#string/checklistsetup"
android:textAlignment="center"
android:textSize="#dimen/text_size"
android:textStyle="bold" />
<ListView
android:id="#+id/lvCheckList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="8" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="#string/lblSoru"
android:textSize="25sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/lblPuan"
android:textSize="25sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_weight="9"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="10"
android:inputType="number"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnAdd"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnCHSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/strSave" />
<Button
android:id="#+id/btnCLClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/strOFF" />
</LinearLayout>
If you use weight on each element with will also cause spaces. So use for object for important.