Creating a longer page in Android Studio - android

I am creating a revision app and I want to add notes to the app.
How do I add lots of text to one screen (I have already tried adding a TextView but there is not enough room to fit it all in is there a way to make the screen longer (with a scroll down))?
I am new to android and your help will be appreciated.

use scrollview inside linearlayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/scrollView1"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="mytexts"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
</ScrollView>
</LinearLayout>

Yes you can make your screen scrollabel by adding just a few lines in
AndroidManifest.xml. Here is an example.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<WebView
android:layout_width="match_parent"
android:layout_height="540dp"
android:id="#+id/webView"
android:layout_gravity="center_horizontal" />
<Button
android:layout_height="fill_parent"
android:layout_width="125dp"
android:text="Forward"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:id="#+id/button"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:id="#+id/button2"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right"
android:id="#+id/button3"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="eft"
android:id="#+id/button4"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cam0"
android:id="#+id/button5"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</RelativeLayout>
</ScrollView>

<ScrollView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"/>
</ScrollView>
set width and height to wrap_content and singleLine to false;

Related

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

EditText on focus scroll up without resize other views

I'm trying to get an EditText field to scroll over my cameraPreview when selected. However it is now resizing the cameraPreview. I would be content with a adjustPan behaviour however I want the actionBar to stay on screen. I suspect it could be done with a scrollView however uptill no I can't prevent the cameraPreview from resizing.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<FrameLayout
android:id="#+id/cameraPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" >
</FrameLayout>
<!-- Fix for black overlay on menu -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" >
</FrameLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"
>
<EditText
android:id="#+id/inputCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/White"
android:ems="10"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:textColor="#color/Green"
android:textSize="32sp"
android:layout_alignParentBottom="true" >
</EditText>
</ScrollView>
Finally decided to scroll the whole view including the action bar
I have been searching for the solution for a long time ,finally I got it;
It's simple,
First, use scroll_view as your View which has a edit_text child;
Second, use a Relative_Layout(Linear_Layout is useless) as the child of your Scroll_View
Then,you can see it works
notes: (1)Do not use layout_align_Parent_Bottom ,user layout_below instead
(2)You have no need to specify window_Soft_Input_Model,the default is OK;
here is the example
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rootlinearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="500dp"
android:text="#string/hello_world" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Button1" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button6" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/scrollView1"
android:ems="10" >
</EditText>
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button8" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button9" />
<Button
android:id="#+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button10" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/captionbottomrelativelayout"
android:layout_width="320dp"
android:layout_height="44dp"
android:layout_below="#+id/scrollView1"
android:orientation="horizontal" >
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Button" />`enter code here`
</LinearLayout>
`enter code here
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"
add the above line in your manifest activity.

Put buttons at bottom of screen with LinearLayout?

I have the following code, how do I make it so that the 3 buttons are at the bottom?
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center"
android:text="#string/observer"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:context=".asdf"
android:weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="1" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="2" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="3" />
</LinearLayout>
You need to ensure four things:
Your outside LinearLayout has layout_height="match_parent"
Your inside LinearLayout has layout_weight="1" and layout_height="0dp"
Your TextView has layout_weight="0"
You've set the gravity properly on your inner LinearLayout: android:gravity="center|bottom"
Notice that fill_parent does not mean "take up all available space". However, if you use layout_height="0dp" with layout_weight="1", then a view will take up all available space (Can't get proper layout with "fill_parent").
Here is some code I quickly wrote up that uses two LinearLayouts in a similar fashion to your code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/cow"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="1" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="2" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="3" />
</LinearLayout>
</LinearLayout>
The result looks like similar to this:
You can use a RelativeLayout and align it to the bottom with android:layout_alignParentBottom="true"
Create Relative layout and inside that layout create your button with this line
android:layout_alignParentBottom="true"
You can do this by taking a Frame layout as parent Layout and then put linear layout inside it. Here is a example:
<FrameLayout 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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textSize="16sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textSize="16sp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textSize="16sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textSize="16sp"/>
</LinearLayout>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="bottom"
/>
</FrameLayout>
first create file name it as footer.xml
put this code inside it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="78dp"
android:layout_gravity="bottom"
android:gravity="bottom"
android:layout_weight=".15"
android:orientation="horizontal"
android:background="#drawable/actionbar_dark_background_tile" >
<ImageView
android:id="#+id/lborder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/overlay" />
<ImageView
android:id="#+id/unknown"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/notcolor" />
<ImageView
android:id="#+id/open"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/openit"
/>
<ImageView
android:id="#+id/color"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/colored" />
<ImageView
android:id="#+id/rborder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/frames"
android:layout_weight=".14" />
</LinearLayout>
then create header.xml and put this code inside it.:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="#dimen/action_bar_height"
android:layout_gravity="top"
android:baselineAligned="true"
android:orientation="horizontal"
android:background="#drawable/actionbar_dark_background_tile" >
<ImageView
android:id="#+id/contact"
android:layout_width="37dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_weight=".18"
android:scaleType="fitCenter"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/logo"/>
<ImageView
android:id="#+id/share"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/share" />
<ImageView
android:id="#+id/save"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/save" />
<ImageView
android:id="#+id/set"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/set" />
<ImageView
android:id="#+id/fix"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/light" />
<ImageView
android:id="#+id/rotate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/ic_menu_rotate" />
<ImageView
android:id="#+id/stock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".14"
android:background="#drawable/action_bar_left_button"
android:src="#drawable/stock" />
</LinearLayout>
and then in your main_activity.xml and put this code inside it :-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:id="#+id/relt"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="78dp"
android:id="#+id/down"
android:layout_alignParentBottom="true" >
<include
android:layout_width="fill_parent"
android:layout_height="78dp"
layout="#layout/footer" >
</include>
</LinearLayout>
<ImageView
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/down"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/inc"
>
</ImageView>
<include layout="#layout/header"
android:id="#+id/inc"
android:layout_width="fill_parent"
android:layout_height="50dp"></include>
happy coding :)
<LinearLayout
android:id="#+id/LinearLayouts02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom|end">
<TextView
android:id="#+id/texts1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="2"
android:text="#string/forgotpass"
android:padding="7dp"
android:gravity="bottom|center_horizontal"
android:paddingLeft="10dp"
android:layout_marginBottom="30dp"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="50dp"
android:fontFamily="sans-serif-condensed"
android:textColor="#color/colorAccent"
android:textStyle="bold"
android:textSize="16sp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</LinearLayout>
Just add layout_weight="1" to in your linearLayout which having Buttons.
Edit :- let me make it simple
follow something like below, tags name may not be correct, it is just an Idea
<LL>// Top Parrent LinearLayout
<LL1 height="fill_parent" weight="1" "other tags as requirement"> <TV /><Butons /></LL1> // this layout will fill your screen.
<LL2 height="wrap_content" weight="1" orientation="Horizontal" "other tags as requirement"> <BT1 /><BT2/ ></LL2> // this layout gonna take lower part of button height of your screen
<LL/> TOP PARENT CLOSED
You can bundle your Button(s) within a RelativeLayout even if your Parent Layout is Linear. Make Sure the outer most parent has android:layout_height attribute set to match_parent.
And in that Button tag add
'android:alignParentBottom="True" '
You can use the Space widget with layout_weight=1 to fill up the space between your widgets and the bottom buttons. See example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/date_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:hint="#string/date_hint">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/date_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/time_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:hint="#string/time_hint">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/time_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:inputType="datetime" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/food_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="#string/food_hint">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/food_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/calories_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="#string/calories_hint">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/calories_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/add_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/add_button" />
</LinearLayout>
Add android:windowSoftInputMode="adjustPan" to manifest - to the corresponding activity:
<activity android:name="MyActivity"
...
android:windowSoftInputMode="adjustPan"
...
</activity>
In my case I was trying to put a complete Linear Layout at the bottom in Linear Layout. When I tried using the "layout_gravity" to bottom it was not working. So I changed the root layout to the Frame Layout and it worked perfectly.
So If you want to put a layout at bottom try using Frame Layout and put everything else inside a nested Linear or Relative Layout.

buttons are not displayed

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">

Categories

Resources