Alignment problems in XML - android

I'm Trying to get the buttons to go under the white box. In the java file I am adding a special view to the id:ViewLayout. I have tried putting the buttons after the Framelayout, but they dont appear on screen....
<TextView
android:id="#+id/tvClock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="12:00"
android:textColor="#android:color/white"
android:textSize="100dp" />
<FrameLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/ViewLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</RelativeLayout>
<Button
android:id="#+id/bUnlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock" />
<Button
android:id="#+id/bPin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PIN" />
</FrameLayout>
Thanks!

Try this one.
<?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="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/black"
android:orientation="vertical" >
<TextView
android:id="#+id/tvClock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="12:00"
android:textColor="#android:color/white"
android:textSize="100dp" />
<LinearLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.58" >
<LinearLayout
android:id="#+id/ViewLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>

<TextView
android:id="#+id/tvClock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="12:00"
android:textColor="#android:color/white"
android:textSize="100dp" />
<RelativeLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/ViewLayout"
android:layout_width="match_parent"
android:layout_height="100dp" >
</RelativeLayout>
<Button
android:id="#+id/bUnlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock"
android:layout_below="#id/ViewLayout"
/>
<Button
android:id="#+id/bPin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PIN"
android:layout_below="#id/bUnlock"/>
</RelativeLayout>
Try RelativeLayout instead of framelayout.

This may help you:
<TextView
android:id="#+id/tvClock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center"
android:text="12:00"
android:textColor="#android:color/white"
android:textSize="100dp"
android:layout_weight="2" />
<LinearLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/ViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="#+id/bUnlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock" />
<Button
android:id="#+id/bPin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PIN" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Related

Linear layout below the ListView, Some portions not visible?

I have a problem with LinearLayout which is below the listview. I tried to give the listview weight and layout above, set the layout_height to 0dp but nothing wotked.
Here is my XML 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"
android:weightSum="100"
android:background="#00c4ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Application № - "
android:layout_weight="50"/>
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="__"
android:layout_weight="20" />
<EditText
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:hint="dd/mm/yyyy"
android:layout_weight="30"
/>
</LinearLayout>
<ListView
android:id="#+id/lvMain"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom"
android:id="#+id/ll">
<Button
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/comment"
android:inputType="text"
android:hint="Comment" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="bottom">
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
<Button
android:id="#+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save and close"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
when ListView fills the screen, I cannot see the buttons below to it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:background="#00c4ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Application № - "
android:layout_weight="50"/>
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="__"
android:layout_weight="20" />
<EditText
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:hint="dd/mm/yyyy"
android:layout_weight="30" />
</LinearLayout>
<ListView
android:id="#+id/lvMain"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="90">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:orientation="vertical"
android:gravity="bottom"
android:id="#+id/ll">
<Button
android:id="#+id/plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/comment"
android:inputType="text"
android:hint="Comment" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="bottom">
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
<Button
android:id="#+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save and close"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Your layout edited by adding layout weights. Please check.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:weightSum="100"
android:background="#00c4ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Application № - "
android:layout_weight="50"/>
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="__"
android:layout_weight="20" />
<EditText
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:hint="dd/mm/yyyy"
android:layout_weight="30"
/>
</LinearLayout>
<ListView
android:id="#+id/lvMain"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="0.3"
android:gravity="bottom"
android:id="#+id/ll">
<Button
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/comment"
android:inputType="text"
android:hint="Comment" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="bottom">
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
<Button
android:id="#+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save and close"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
You should try List View with Layout having weight.
Sample Code:
<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="0dp"
android:layout_weight="0.3"
/>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
>
<ListView
android:id="#+id/lvMain"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
/>
</LinearLayout>
In this your height is fixed for listview. Assuming that you can use list view as srollable in particular height.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/topLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alignParentTop="true"
android:weightSum="100"
android:background="#00c4ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Application № - "
android:layout_weight="50"/>
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="__"
android:layout_weight="20" />
<EditText
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:hint="dd/mm/yyyy"
android:layout_weight="30"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom"
android:alignParentBottom="true"
android:id="#+id/ll">
<Button
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/comment"
android:inputType="text"
android:hint="Comment" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="bottom">
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
<Button
android:id="#+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save and close"/>
</LinearLayout>
</LinearLayout>
<ListView
android:id="#+id/lvMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/topLayout"
android:layout_above="#+id/bottomLayout">
</ListView>
</RelativeLayout>
Have edited your code. Try this.
Here in this I have used RelativeLayout, so that we use android:alignParentBottom="true" for bottom layout which makes the layout in fix in bottom. Simillarly we can do for top layout using android:alignParentBottom="true". Now coming to ListView, which we need to place between top and bottom layout I have used the following code to achieve it
android:layout_below="#+id/topLayout"
android:layout_above="#+id/bottomLayout"
This makes the ListView to stick in between the top and bottom layout.
Hope this is helpful:)
Change as below
<?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"
android:background="#00c4ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Application № - "
android:layout_weight="50"/>
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="__"
android:layout_weight="20" />
<EditText
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:hint="dd/mm/yyyy"
android:layout_weight="30"
/>
</LinearLayout>
<ListView
android:id="#+id/lvMain"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom"
android:id="#+id/ll">
<Button
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/comment"
android:inputType="text"
android:hint="Comment" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom">
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
<Button
android:id="#+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save and close"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

ScrollView is not scrolling overflowed layout

I have a scroll view containing one child layout(linear layout) and that child contains a relative layout and a linear layout. Relative layout and linear layout shares half-half screen. Linear layout has buttons added to it dynamically.
Now problem arises as scroll view does not scroll buttons while it scrolls relative layout and linear layout.
<ScrollView>
<LinearLayout>
<RelativeLayout>
</RelativeLayout>
<LinearLayout>
->Dynamically adding buttons here
</LinearLayout>
</LinearLayout>
</ScrollView>
I want those buttons scroll with scrollview
For reference my xml code is :-
<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="#color/whitecolor"
android:orientation="vertical"
>
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
>
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bluecolor"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/stauslinearlayout"
android:layout_marginBottom="8dp"
android:padding="5dp"
android:gravity="center"
android:textColor="#color/whitecolor"
android:text="#string/app_name"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:background="#color/bluecolor"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/edit_text_custom"
android:singleLine="true"
android:hint="#string/status"
android:textColor="#000"
android:textColorHint="#5222"
android:padding="7dp"
android:maxLength="50"
android:cursorVisible="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:drawableLeft="#android:drawable/ic_input_add"
android:ems="10"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:gravity="center"
android:layout_weight="0"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:padding="5dp"
android:text="#string/statusnumber"
android:background="#drawable/edit_text_custom"
/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/whitecolor"
android:text="abcdfrg"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
AFAIK, If you want to divide screen in to same two sizes, you have to take another scrollView in bottom view, like below example...
<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" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/stauslinearlayout"
android:layout_marginBottom="8dp"
android:gravity="center"
android:padding="5dp"
android:text="#string/app_name"
android:textColor="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/darker_gray"
android:orientation="horizontal" >
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:cursorVisible="true"
android:drawableLeft="#android:drawable/ic_input_add"
android:ems="10"
android:hint="status"
android:maxLength="50"
android:padding="7dp"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#5222" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0"
android:gravity="center"
android:padding="5dp"
android:text="statusnumber" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:text="abcdfrg" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
and if you don't want to take another scrollView, then you have to give wrap_contant to bottom linear-layout.
<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" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/stauslinearlayout"
android:layout_marginBottom="8dp"
android:gravity="center"
android:padding="5dp"
android:text="#string/app_name"
android:textColor="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/darker_gray"
android:orientation="horizontal" >
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:cursorVisible="true"
android:drawableLeft="#android:drawable/ic_input_add"
android:ems="10"
android:hint="status"
android:maxLength="50"
android:padding="7dp"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#5222" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0"
android:gravity="center"
android:padding="5dp"
android:text="statusnumber" />
</LinearLayout>
</RelativeLayout>
<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:background="#android:color/white"
android:text="abcdfrg" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
choice goes to your requirement.
if any problem yet, then plz ask... :-)

Android map with custom layout

I' am trying to achieve sth like this:
But the ListView is overlaps my bottom bar. What is the best way to prevent such a behaviour? As you can see in the picture there is a map under bottom bar. This bottom bar is like target/destination window in Google Maps app.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<com.google.android.gms.maps.MapView
android:id="#+id/map"
tools:layout="#layout/fragmentMap"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical">
<EditText
android:id="#+id/mapEditT"
android:layout_width="fill_parent"
android:layout_height="53dp"
android:layout_alignParentTop="true"
android:gravity="center|left"
android:paddingLeft="2dp"
android:paddingRight="0dp"/>
<ListView
android:id="#+id/listVi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<ImageButton
android:id="#+id/draweR"
android:layout_width="wrap_content"
android:src="#drawable/draweR"/>
<LinearLayout
android:id="#+id/infoBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="40dp"
android:alpha="0.1"
android:background="#android:color/black"
android:orientation="horizontal">
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="Info"
/>
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_toRightOf="#id/text2"
android:text="Info/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
Use LinearLayout or RelativeLayout as top most parent instead of FrameLayout.
Here is the code snippet using LinearLayout.
<?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" >
<EditText
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/draweR"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="#drawable/draweR"/>
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragmentMap" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100" >
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_weight="75" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_weight="25" />
</LinearLayout>
</LinearLayout>
You can mess around with the margins. I got it to look like the image you wanted.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragmentMap" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical"
android:paddingBottom="160dp" >
<EditText
android:id="#+id/mapEditT"
android:layout_width="fill_parent"
android:layout_height="53dp"
android:layout_alignParentTop="true"
android:gravity="center|left"
android:paddingLeft="2dp"
android:paddingRight="0dp" />
<ListView
android:id="#+id/listVi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical" >
<ImageButton
android:id="#+id/draweR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/draweR" />
<LinearLayout
android:id="#+id/infoBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:alpha="0.1"
android:background="#android:color/black"
android:orientation="horizontal" >
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="Info" />
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_toRightOf="#id/text2"
android:text="Info" />
</LinearLayout>
</LinearLayout>

Relative layout bottom align issue

I'm trying to implement a relative layout, similar to below picture.
But when trying to bottom align the bottom-right text view, it goes out of the screen.
What is the best/minimal way to design below layout?
Code, currently I'm trying:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/dash1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top" >
<RelativeLayout
android:id="#+id/view_subdash_top_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/tv_name" >
<TextView
android:id="#+id/tv_instrument_change"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_text2"
android:gravity="right"
android:text="text1" />
<TextView
android:id="#+id/tv_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="right"
android:text="text2" />
</RelativeLayout>
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="#id/view_subdash_top_right"
android:gravity="bottom|center"
android:text="name" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/dash1"
android:gravity="top" >
<!-- Here to enter bottom left -->
<TextView
android:id="#+id/tv_bottom_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="right|bottom"
android:text="bottom right" />
</RelativeLayout>
</RelativeLayout>
// try this
<?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"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rel_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/rel_top_right"
android:text="Top Left Text" />
<RelativeLayout
android:id="#+id/rel_top_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:layout_toRightOf="#id/tv_top_left" >
<TextView
android:id="#+id/tv_top_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top Text1" />
<TextView
android:id="#+id/tv_top_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_top_text1"
android:text="Top Text2" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rel_top"
android:gravity="top" >
<TextView
android:id="#+id/tv_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="#id/rel_bottom_left"
android:text="Bottom Right Text" />
<RelativeLayout
android:id="#+id/rel_bottom_left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/tv_bottom_right" >
<TextView
android:id="#+id/tv_bottom_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom Text1" />
<TextView
android:id="#+id/tv_bottom_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_bottom_text1"
android:text="Bottom Text2" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
If you want to fill up the whole screen with those views, I'd use weighted LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"/>
</LinearLayout>
</LinearLayout>

Android Button Place Image in center and text at bottom

I want to place Image in the center and text just below it in a button, I tried to set android:gravity but could not set it properly,here is the image attached:
below is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="10.0dip"
android:paddingTop="10.0dip"
android:paddingRight="10.0dip"
android:paddingBottom="10.0dip"
android:background="#drawable/background_img"
>
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="10.0dip"
android:paddingTop="10.0dip"
android:paddingRight="10.0dip"
android:paddingBottom="10.0dip"
>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:id="#+id/button_listen"
android:text="#string/listen"
android:drawableTop="#drawable/listen_btn"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"
/>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:id="#+id/button_gallery"
android:text="#string/gallery"
android:drawableTop="#drawable/gallery_btn"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="10.0dip"
android:paddingTop="10.0dip"
android:paddingRight="10.0dip"
android:paddingBottom="10.0dip"
>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:id="#+id/button_play"
android:text="#string/play"
android:drawableTop="#drawable/play_btn"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:id="#+id/button_find"
android:text="#string/find"
android:drawableTop="#drawable/test_btn"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"
/>
</LinearLayout>
</LinearLayout>
What is the proper way to center the image and text below it?
Many thanks in advance.
Try this its work for me
<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=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="151dp"
android:onClick="onClick"
android:drawableTop="#drawable/ic_launcher"
android:text="Button" />
</RelativeLayout>
Try change the button to LinearLayout and use same onclicklistener on fakebutton
<LinearLayout
android:id="#+id/fakeButton"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_big_evento" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/menu_about" />
</LinearLayout>
I followed DjHacktorReborn comments and made the layout, here is the freezed one
<?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:background="#drawable/background_img"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4.1"
android:orientation="vertical" >
</LinearLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal"
android:stretchColumns="*" >
<TableRow android:layout_weight="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button_listen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="#drawable/main_list"
android:paddingTop="90dp"
android:text="#string/listen"
android:textStyle="bold"
android:textColor="#FFFFFF" />
<ImageView
android:id="#+id/main_icon_content_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/listen_btn" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_list"
android:paddingTop="90dp"
android:text="#string/gallery"
android:textStyle="bold"
android:textColor="#FFFFFF" />
<ImageView
android:id="#+id/main_icon_schedule_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/gallery_btn" />
</RelativeLayout>
</TableRow>
<TableRow android:layout_weight="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button_play"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_list"
android:ellipsize="marquee"
android:paddingTop="90dp"
android:text="#string/play"
android:textStyle="bold"
android:textColor="#FFFFFF"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/play_btn" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button_find"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_list"
android:paddingTop="90dp"
android:text="#string/find"
android:textStyle="bold"
android:textColor="#FFFFFF" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/test_btn" />
</RelativeLayout>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4.1"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
Here is the updated result
Thanks for the suggestions

Categories

Resources