Custom dialog sometimes don't fit the screen - android

I made custom dialog in my app and it looks like this:
And "TEXT" is simply TextView inside a ScrollView. Height of everything is "wrap_content" to match the content and don't match the whole screen unnecessary. And everything is ok untill the text is too big and I have to scroll. Then my down part of dialog is gone and now dialog looks like this:
How can I make this work well to be like this all the time?
Here is the code of my custom dialog layout:
<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:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="0dp"
tools:context="com.baddevelopergames.taboopremiumrebuild.DialogActivity">
<ImageView
android:background="#drawable/ramkahg"
android:alpha="0.8"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="TEXT"
android:textColor="#000000"
android:background="#019d92"
android:alpha="0.8"
android:id="#+id/d1_infoTextView"
android:textSize="15sp"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="#019d92"
android:alpha="0.8"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="BUTTON 1"
android:id="#+id/d1_leftButton"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:text="BUTTON 2"
android:id="#+id/d1_rightButton"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:background="#drawable/ramkahd"
android:alpha="0.8"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

If you want the buttons to be always on the bottom, and TEXT always above, I think you should use a RelativeLayout instead. Try with these xml
<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:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="0dp"
tools:context="com.baddevelopergames.taboopremiumrebuild.DialogActivity">
<ImageView
android:background="#drawable/ramkahg"
android:alpha="0.8"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_above="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:text="TEXT"
android:textColor="#000000"
android:background="#019d92"
android:alpha="0.8"
android:id="#+id/d1_infoTextView"
android:textSize="15sp"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
<LinearLayout
android:id="#+id/buttons"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="#019d92"
android:alpha="0.8"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:text="BUTTON 1"
android:id="#+id/d1_leftButton"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:text="BUTTON 2"
android:id="#+id/d1_rightButton"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:background="#drawable/ramkahd"
android:alpha="0.8"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

Related

How to place two Seeksbars at one place?

Here what I am doing is , I want to show the seekbar running in between the RangeSeekBar (between the selected range). For that, I want to place these two seekbars at one position.
I don't know how to do that. I have tried RelativeLayout and FrameLayout but nothing happened.
Thank you.
activity_play.xml
<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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<SeekBar
android:id="#+id/pSeekBar"
android:layout_width="match_parent"
android:layout_height="37dp" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/screen_background_light"
android:orientation="vertical"
android:padding="10dip">
<TextView
android:id="#+id/selectedfile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="center_horizontal"
android:singleLine="true"
android:text="Not file selected"
android:textColor="#android:color/black" />
<com.yahoo.mobile.client.android.util.rangeseekbar.RangeSeekBar
android:id="#+id/rangeSeekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
android:paddingBottom="10dip"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/screen_background_light"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/MinEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_media_previous" />
<ImageButton
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_media_next" />
<EditText
android:id="#+id/MaxEdiText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
u can use this library its hard to write it yourself
https://github.com/syedowaisali/crystal-range-seekbar

How to achieve a layout in Android studio with two Layouts

I am trying to achieve the below layout but I am not sure how I can split / have two layouts on one screen, with one being empty and one containing other elements. Like shown in the image below, I want to have layout 1 that contains other elements and layout that is empty. With a divider line between the two layouts.
Any help would be nice, I am not sure where to start. I have came accross having two layouts on 1 screen and splitting them to about 40:60 ratio.
Try to use
<?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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.rushabh_pc.lin.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label2"
android:id="#+id/toggleButton"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:checked="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label 3"
android:id="#+id/lab3"
android:layout_below="#+id/toggleButton"
android:layout_toLeftOf="#+id/toggleButton"
android:layout_toStartOf="#+id/toggleButton" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label 4"
android:layout_alignBaseline="#+id/lab3"
android:layout_alignBottom="#+id/lab3"
android:layout_toRightOf="#+id/toggleButton"
android:layout_toEndOf="#+id/toggleButton"
android:id="#+id/l4"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="last"
android:layout_below="#id/l4"/>
</RelativeLayout>
Code Below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main3"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.staff.app.Main3Activity"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_orange_light">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textView"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textView"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textView1"/>
<LinearLayout
android:id="#+id/linearLyout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="editText1"
android:layout_weight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="editText2"
android:layout_weight="1"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textView"
android:textSize="40dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/linearLyout"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black"></View>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"></RelativeLayout>
</LinearLayout>
Use LinearLayout with layout_weight to specify the ratio for the space occupied by each child layout. For a 40:60 split, use the below
<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="0dp"
android:layout_weight="0.4"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/holo_green_light"
android:text="Label"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/holo_blue_bright"
android:text="Label"
android:textSize="30sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_weight="1"
android:background="#android:color/holo_green_light"
android:hint="Textbox1" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_weight="1"
android:background="#android:color/holo_green_light"
android:hint="Textbox2" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0sp"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"
android:text="Label" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6"></LinearLayout>
</LinearLayout>

Equal width of all buttons

I want to achieve the following layout.
How do I make the button 0 equal to rest of the buttons. Please note that I have used layout_weight = "1" so that all of the rest of the buttons are of equal length while matching the parent. Since, I have created button 0 on a different layout so I can't seem to make it of equal length with other buttons.
Here's my code so far
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/seven"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/eight"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/nine"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Take the zero button out of the LinearLayout, I assume there is another layout all this are defined in, like a relative layout? and try something to this effect.
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<Button
android:id="#+id/seven"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/eight"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/nine"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:layout_marginTop="98dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
Take the last button in another linearlayout and further add linearlayout in it with weight, try this code....
<?xml version="1.0" encoding="utf-8"?>
<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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/seven"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button
android:id="#+id/eight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button
android:id="#+id/nine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:id="#+id/zero"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
here is the output

Put button in the bottom of the layer

I'm trying to put those two buttons in the bottom of my layer. But when I put the gravity of them to "bottom" nothing happens. Please help me.
I have tried to put the gravity of my second linearLayout "bottom" too with wrap_content as height but still not working.
[![<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.emmanuilvaresis.oldiefinder.AppSettings"
android:orientation="vertical"
android:background="#drawable/background_img">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:textSize="22sp"
android:text="#string/keyword"
android:id="#+id/lblKeyword"
android:textColor="#ffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtKeyword"
android:textSize="20sp"
android:textColor="#cacaca" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:textSize="22sp"
android:text="#string/number"
android:id="#+id/lblNumber"
android:textColor="#ffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtNumber"
android:textSize="20sp"
android:textColor="#cacaca" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:textSize="22sp"
android:text="#string/address"
android:id="#+id/lblAddress"
android:textColor="#ffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtAddress"
android:textSize="20sp"
android:textColor="#cacaca"
android:hint="#string/addresshint"
android:textColorHint="#cacaca" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btnOK"
android:text="#string/btnOK"
android:layout_gravity="bottom" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btnCancel"
android:text="#string/btncancel"
android:layout_gravity="bottom|center" />
</LinearLayout>
</LinearLayout>][1]][1]
layout_gravity doesnt work with LinearLayout. You should use FrameLayout for parent of the view which has layout_gravity attributes.
<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:background="#drawable/background_img"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.emmanuilvaresis.oldiefinder.AppSettings">
<TextView
android:id="#+id/lblKeyword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/keyword"
android:textColor="#ffffff"
android:textSize="22sp"
android:textStyle="italic" />
<EditText
android:id="#+id/txtKeyword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#cacaca"
android:textSize="20sp" />
<TextView
android:id="#+id/lblNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/number"
android:textColor="#ffffff"
android:textSize="22sp"
android:textStyle="italic" />
<EditText
android:id="#+id/txtNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#cacaca"
android:textSize="20sp" />
<TextView
android:id="#+id/lblAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/address"
android:textColor="#ffffff"
android:textSize="22sp"
android:textStyle="italic" />
<EditText
android:id="#+id/txtAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/addresshint"
android:textColor="#cacaca"
android:textColorHint="#cacaca"
android:textSize="20sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:orientation="vertical">
<Button
android:id="#+id/btnOK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btnOK" />
<Button
android:id="#+id/btnCancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btncancel" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
You want to place a horizontal linear layout with two buttons at the bottom of screen.
You can simply wrap the remaining content in to vertical linear layout and set its layout_weight as 1.
Sample code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//REPLACE BELOW CODE WITH YOUR REMAINING CODE WRAPPED INSIDE A LINEAR LAYOUT, APART FROM THOSE BUTTONS.
<include
layout="#layout/YOUR_REMAINING_CONTENT"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0" />
//YOUR LINEARLAYOUT WITH BUTTONS WHICH NEEDS TO STAY AT BOTTOM.
<include layout="#layout/YOUR_BOTTOM_CONTENT"/>
</LinearLayout>

Why my element is not staying at the bottom as supposed?

I have this layout xml file:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_marginTop="40dp"
android:id="#+id/emalLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/test" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/testTxtLay"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/emalLbl"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1">
<EditText
android:id="#+id/testTxt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#drawable/edit_text_design" />
</LinearLayout>
<TextView
android:layout_marginTop="60dp"
android:id="#+id/reminderLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/testTxtLay"
android:layout_centerHorizontal="true"
android:text="#string/reminder" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginTop="10dp"
android:id="#+id/reminderTxtLay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/reminderLbl"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1">
<EditText
android:id="#+id/reminderTxt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:lines="2"
android:background="#drawable/edit_text_design" />
</LinearLayout>
<View
android:id="#+id/spacer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#id/reminderTxtLay"
android:layout_centerHorizontal="true" />
<Button
android:layout_marginTop="200dp"
android:id="#+id/pickDateBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/reminderTxtLay"
android:layout_toLeftOf="#+id/spacer"
android:onClick="showDatePickerDialog"
android:text="#string/datePickerBtnTxt" />
<Button
android:id="#+id/pickTimeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/pickDateBtn"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/pickDateBtn"
android:onClick="showTimePickerDialog"
android:text="#string/pickTimeBtn" />
<View
android:id="#+id/spacerTxt"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#id/reminderTxtLay"
android:layout_centerHorizontal="true" />
<EditText
android:layout_marginTop="15dp"
android:id="#+id/selectedDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/spacerTxt"
android:layout_below="#id/pickDateBtn"
android:layout_toLeftOf="#+id/spacerTxt" />
<EditText
android:id="#+id/selectedTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/selectedDate"
android:layout_below="#id/pickTimeBtn"
android:layout_toRightOf="#+id/selectedDate" />
<Button
android:id="#+id/submitBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:onClick="submitData"
android:text="#string/submitBtn" />
</RelativeLayout>
</ScrollView>
This is the custom design for 7 inch tablets, placed in res\layout-sw600dp
Anyways in the android studio landscape preview it seems just fine:
But in the emulator something is going wrong and here is how it looks strange. What I mean is that the submit button is not on the bottom and the pickDate and pickTime buttons are at the bottom of the layout.
I know that I'm missing a basic point here, but as an android developer, I'm not able to spot it.
Can you give me a push?
Here is a complete way to do what you seem to try accomplish. You don't need to create any Views for "spaces" etc. You only need to add margin or padding to either side of your views to make it move away from another view.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:id="#+id/linear_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<TextView
android:layout_marginTop="40dp"
android:id="#+id/emalLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/test" />
<EditText
android:id="#+id/testTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_text_design" />
<TextView
android:layout_marginTop="60dp"
android:id="#+id/reminderLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/reminder" />
<EditText
android:id="#+id/reminderTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="2"
android:background="#drawable/edit_text_design" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="200dp"
>
<Button
android:id="#+id/pickDateBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="showDatePickerDialog"
android:text="#string/datePickerBtnTxt" />
<Button
android:id="#+id/pickTimeBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="showTimePickerDialog"
android:text="#string/pickTimeBtn" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/selectedDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<EditText
android:id="#+id/selectedTime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/submitBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_below="#+id/linear_wrapper"
android:onClick="submitData"
android:text="#string/submitBtn" />
</RelativeLayout>
you can place 2 buttons next to each other!
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1">
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:gravity="left"
android:layout_height="wrap_content"
android:lines="2" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:gravity="right"
android:layout_height="wrap_content" />
</LinearLayout>

Categories

Resources