buttons are not displayed - android

This is my xml code (i followed this post, but its not working):
<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" >
<WebView
android:id="#+id/webChapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_below="#+id/webChapter"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/btnMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back To Menu" />
<Button
android:id="#+id/btnNavi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example" />
<Button
android:id="#+id/btnQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quiz" />
</LinearLayout>
And this is the graphical one :
My buttons are not displayed when my webview become too tall. What should i do? Thanks :D

Try the following:
<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" >
<WebView
android:id="#+id/webChapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/linearlayout"/>
<LinearLayout
android:id="#+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/btnMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back To Menu" />
<Button
android:id="#+id/btnNavi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example" />
<Button
android:id="#+id/btnQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quiz" />
</LinearLayout>
Hope this will help you

hi try this following one
<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" >
<WebView
android:id="#+id/webChapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/btnLayout"/>
<LinearLayout
android:id="#+id/btnLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_below="#+id/webChapter">
<Button
android:id="#+id/btnMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back To Menu" />
<Button
android:id="#+id/btnNavi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example" />
<Button
android:id="#+id/btnQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quiz" />
</LinearLayout>

Try below Layout, Hope it works for you.
<LinearLayout 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:weightSum="10" >
<WebView
android:id="#+id/webChapter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_horizontal" >
<Button
android:id="#+id/btnMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back To Menu" />
<Button
android:id="#+id/btnNavi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example" />
<Button
android:id="#+id/btnQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quiz" />
</LinearLayout>
</LinearLayout>
Above code will have buttons down the webview. If you can use the buttons above the webview, then there is no need of using weights also. you can put webview below the buttons layout.

You may fix a height to your webview, or maybe define an id to your LinearLayout and set the property android:layout_above on your webView to guarantee that your webview will be above buttons not floating over them.
Try something like this:
<WebView
android:id="#+id/webChapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/lowerBar"
android:layout_alignParentTop="true"/>
<LinearLayout
android:id="#+id/lowerBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true">

Related

Buttons are not shown in real device but shown in emulator in android

I have a linearlayout which has 2 buttons cancel & download which are use to cancel or download of image respectively. When I run the app on emulator [Emulator is Nexus-5] all works fine , these 2 buttons are shown, but when I test my app on real device [My device is samsung-core].
Image is loaded from internet and then this liearLayout is shown, initially it is hidden.
This is the screenshot from my device
And this is my emulator screenshot
This is layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="#+id/et_pic_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter pic url here" />
<Button
android:id="#+id/bt_pic_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_download_cancel_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:paddingRight="32dp">
<Button
android:id="#+id/bt_cancel_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="#+id/bt_pic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Download" />
</LinearLayout>
I am guessing this is happening because of Screen Height. But why this 2 buttons get hidden.What is making this weird thing happen in my layout file.
Thanks - Suraj
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightsum="10"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:padding="16dp"
android:weight="1"
>
<EditText
android:id="#+id/et_pic_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter pic url here" />
<Button
android:id="#+id/bt_pic_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:weight="8"
>
<ImageView
android:id="#+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_download_cancel_button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:paddingRight="32dp">
<Button
android:id="#+id/bt_cancel_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="#+id/bt_pic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Download" />
</LinearLayout>
enter code here
Your imageview is match parent, so it cover the screen, use the above code. it will workl fine
try ScrollView. The Buttons may below your ImageView(and set your image view attr "wrap_content") or your layout.
demo below according your code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="#+id/et_pic_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter pic url here" />
<Button
android:id="#+id/bt_pic_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/iv_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_download_cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:paddingRight="32dp">
<Button
android:id="#+id/bt_cancel_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="#+id/bt_pic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Download" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Because there is no space to show the button in the device. do as below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:layout_above="#+id/linear_layout_download_cancel_button"
>
<EditText
android:id="#+id/et_pic_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter pic url here"/>
<Button
android:id="#+id/bt_pic_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send"/>
<ImageView
android:id="#+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_download_cancel_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/bt_cancel_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"/>
<Button
android:id="#+id/bt_pic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Download"/>
</LinearLayout>
</RelativeLayout>

Android dialog with ListView

I have a problem with a dialog with some buttons and a ListView.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:orientation="vertical"
tools:context=".MyApplicationActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/selectContactRecord"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnContactPickerAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableLeft="#android:drawable/ic_menu_add"
android:drawableStart="#android:drawable/ic_menu_add"
android:text="#string/noContact" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="#string/selectBulbs"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item" >
</ListView>
<Button
android:id="#+id/btnTestAddRecord"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/test_bulbs"
android:drawableStart="#drawable/test_bulbs"
android:text="#string/test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="#android:color/black"
android:orientation="horizontal" >
<Button
android:id="#+id/btnCancelAddRecord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_revert"
android:drawableStart="#android:drawable/ic_menu_revert"
android:text="#string/cancel" />
<Button
android:id="#+id/btnSaveAddRecord"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_save"
android:drawableStart="#android:drawable/ic_menu_save"
android:text="#string/save" />
</LinearLayout>
The problem is now, if I have a lot of records in the ListView, the button below disappears and it is not possible to scroll down.
I tried this with a ScrollView, but failed because it is not possible to use that with a ListView.
I want that the buttons below the listview always stay at the bottom and that the ListView is scrollable.
Can somebody please give me a hint?
Change your list view to this:
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item"
It'll make sure the button is layout in the bottom and, the list view take all the height remain
You want this :
I want that the buttons below the listview always stay at the bottom
and that the ListView is scrollable.
For this change this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black">
<TextView
android:id="#+id/tvContactRecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/selectContactRecord"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnContactPickerAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableLeft="#android:drawable/ic_menu_add"
android:drawableStart="#android:drawable/ic_menu_add"
android:text="#string/noContact"
android:layout_below="#+id/tvContactRecord" />
<TextView
android:id="#+id/tvSelectBulbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="#string/selectBulbs"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white"
android:layout_below="#+id/btnContactPickerAdd" />
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item"
android:layout_below="#+id/tvSelectBulbs"
android:layout_above="#+id/btnTestAddRecord" >
</ListView>
<Button
android:id="#+id/btnTestAddRecord"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/test_bulbs"
android:drawableStart="#drawable/test_bulbs"
android:text="#string/test"
android:layout_above="#+id/llBottom" />
<LinearLayout
android:id="#+id/llBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="#android:color/black"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/btnCancelAddRecord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_revert"
android:drawableStart="#android:drawable/ic_menu_revert"
android:text="#string/cancel" />
<Button
android:id="#+id/btnSaveAddRecord"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_save"
android:drawableStart="#android:drawable/ic_menu_save"
android:text="#string/save" />
</LinearLayout>
</RelativeLayout>
You can consider below layout for the solution. You can replace Buttons as per your need.(I have given 2 buttons to simplify the things for you) Also you can also consider taking the buttons in another layout as well if required.
<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="${relativePackage}.${activityClass}" >
<Button
android:id="#+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="My Button 2" />
<Button
android:id="#+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/btn2"
android:text="My Button 1" />
<ListView
android:id="#+id/lstMyListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/btn1" />
</RelativeLayout>

Can't get scrollview to work

my code of the XML file I am currently working in! So what I want is to make it possible to scroll in this screen, however there are currently no objects that fall outside of the screen but they will in the future. Hope This gives enough info for help.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:background="#666666">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Name: "
android:id="#+id/NameView" />
<TextView
android:layout_width="128dp"
android:layout_height="38dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/Name"
android:text="#string/nameString"
android:layout_gravity="center_horizontal"
android:layout_weight="0.75" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:weightSum="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Adress:"
android:id="#+id/AdresView" />
<TextView
android:layout_width="128dp"
android:layout_height="38dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/adressString"
android:id="#+id/Adress"
android:layout_gravity="center_horizontal"
android:layout_weight="0.75" />>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="E-mail:"
android:id="#+id/emailView"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="128dp"
android:layout_height="38dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/emailString"
android:id="#+id/Email"
android:layout_gravity="center_horizontal"
android:layout_weight="0.75" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Mobile:"
android:id="#+id/mobileView" />
<TextView
android:layout_width="128dp"
android:layout_height="38dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/mobileString"
android:id="#+id/Mobile"
android:layout_gravity="center_horizontal"
android:layout_weight="0.75" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit Profile"
android:id="#+id/BeditProfile"
android:layout_gravity="bottom"
android:layout_marginLeft="240dp"
android:onClick="onButtonClick" />
</LinearLayout>
</ScrollView>
You need to use ScrollView instead of LinearLayout then i will be work.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#666666"
android:orientation="vertical"
android:weightSum="1" >
<!-- Your all XML code paste here -->
</LinearLayout>
</ScrollView>
If you want to make a screen scrollable just use a ScrollView.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
...
...
</LinearLayout>
</ScrollView>
The ScrollView must only have one direct child!
Put everything in one ScrollView and you will be able to scroll everything - so the main LinearLayout should be wrapped in a ScrollView

Android - EditText isn't filling up available space in a fragment?

I'm having an issue with my EditText (with id of body) not filling up the available space in my layout. I've been searching everywhere and experimenting with numerous resources, but I just simply can not seem to get it and have been spending hours on literally just this.. I'm guessing there is an issue with how my entire layout is set up, and probably can't just make a tweak in EditText. By the way this layout is being used in a fragment, maybe that changes things? I'm not sure, what do you guys think? Thanks for any and all help! Here is my code:
<?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:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/body" />
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="write those saucy lyrics"
android:layout_marginTop="5dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/btnEmail"
android:alpha="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I'm looking for my design to look like this (taken from my graphical layout editor):
However on my device it looks like this(snapshot from my device):
Try this..
Change android:layout_height="wrap_content" to android:layout_height="0dp"
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />
// 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/title"/>
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="#string/body"
android:layout_marginTop="5dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/btnEmail"
android:alpha="1" />
</LinearLayout>
</LinearLayout>
Make
android:layout_height="match_parent"
instead of
android:layout_height="wrap_content"
in Body edit text
So that it becomes
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:scrollbars="vertical" />
UPDATE:
Plz try following layout
<!-- Put the buttons at the bottom -->
<RelativeLayout
android:id="#+id/rel_lay_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Confirm" />
<Button
android:id="#+id/btnEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:alpha="1"
android:text="Emial" />
</RelativeLayout>
<!-- Put the title layout at the top of parent -->
<LinearLayout
android:id="#+id/lin_lay_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<!-- Occupy rest of the space of screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_above="#id/rel_lay_btn"
android:layout_below="#id/lin_lay_title">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Body" />
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="top"
android:layout_weight="1"
android:scrollbars="vertical" />
</LinearLayout>

Android: How to add a Button under a Button

Right now my xml looks like this:
<LinearLayout 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:orientation="horizontal"
>
<EditText
android:id="#+id/table"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:editable="false"
android:hint="#string/table"
android:text="#string/table"
/>
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/copy"
android:onClick="copy"/>
</LinearLayout>
And I want to add a button right under my already created button. I tried adding another button, but it just puts it in the same line. is it the LinearLayout? if so, how do I fix this?
EDIT: Clarifications, I want my EditBox and Button to be in one line, followed by another EditBox and Button.
This is what you need then, and copy the entire inner LinearLayout to add more lines:
<LinearLayout 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:orientation="vertical" >
<!-- Copy from here -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/table"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:editable="false"
android:hint="#string/table"
android:text="#string/table" />
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="copy"
android:text="#string/copy" />
</LinearLayout>
<!-- To herel, and paste under -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#id/table"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:editable="false"
android:hint="#string/table"
android:text="#string/table" />
<Button
android:id="#id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="copy"
android:text="#string/copy" />
</LinearLayout>
</LinearLayout>
As for doing this using code, it is only if you are not aware of how many you need in total, otherwise, do it in XML.
Try this
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
<EditText
android:id="#+id/table"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:editable="false"
android:hint="#string/table"
android:text="#string/table"
/>
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/table
android:text="#string/copy"
android:onClick="copy"/>
<Button
android:id="#+id/button2"
android:layout_below="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.../>
</LinearLayout>
<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"
>
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/copy"
android:onClick="copy"/>
<EditText
android:id="#+id/table1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_toLeftOf="#id/tableButton"
android:hint="#string/table"
android:text="#string/table"
/>
<Button
android:id="#+id/secondButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tableButton"/>
<EditText
android:id="#+id/table2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_bottom="#id/table1"
android:hint="#string/table"
android:text="#string/table"
/>
</RelativeLayout>
Try change your
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/copy"
android:onClick="copy"/>
into something like this
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/copy"
android:onClick="copy"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.../>
</LinearLayout>
If you want the first button to have the same height as the editbox, then you will need to use Tablelayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/table"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:editable="false"
android:hint="#string/table"
android:text="#string/table" />
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="copy"
android:text="#string/copy" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="copy"
android:text="#string/copy" />
</LinearLayout>

Categories

Resources