How to align the layouts properly in Android? - android

I want to align a scrollable TextView above a RelativeLayout) with 3 buttons at the bottom and a SeekBar above this buttons. The problem with my code is that the RelativeLayout takes the entire screen.
Here's my 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:background="#drawable/images"
android:orientation="vertical"
tools:context="com.example.acer.aartisangrah.ekdanta">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textView9"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:enabled="true"
android:focusable="true"
android:longClickable="true"
android:textIsSelectable="true" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/b9"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:onClick="decrease"
android:background="#drawable/zoomout1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/b10"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="increase"
android:layout_marginRight="10dp"
android:background="#drawable/zoomin1"/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/button19"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/play"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBar"
android:layout_above="#+id/b9"
android:configChanges="orientation|screenSize"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/b10"
android:layout_alignRight="#+id/b10"
android:layout_alignEnd="#+id/b10"
android:layout_weight="1"/>
</RelativeLayout>
</LinearLayout>
Check this image

Change the height of the ScrollView to android:layout_height="wrap_content"
and remove the android:layout_weight="1"

The following layout should do the job. Firstly, there was a circular dependency in height among <RelativeLayout> and <SeekBar>, so I fixed the height of <SeekBar>. Secondly, the android:layout_alightParentBottom="true" was messing with the layout manager, so removed that. Finally, moved the <SeekBar> above the buttons to easily manage the layout description. Here's the updated 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:background="#drawable/images"
android:orientation="vertical"
tools:context="com.example.acer.aartisangrah.ekdanta">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textView9"
android:enabled="true"
android:focusable="true"
android:longClickable="true"
android:textIsSelectable="true" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<SeekBar
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/seekBar"
android:configChanges="orientation|screenSize"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/b10"
android:layout_alignRight="#+id/b10"
android:layout_alignEnd="#+id/b10"/>
<Button
android:id="#+id/b9"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:onClick="decrease"
android:layout_below="#id/seekBar"
android:background="#drawable/zoomout1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/b10"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:onClick="increase"
android:layout_below="#id/seekBar"
android:layout_marginRight="10dp"
android:background="#drawable/zoomin1"/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/button19"
android:layout_below="#id/seekBar"
android:layout_centerHorizontal="true"
android:background="#drawable/play"/>
</RelativeLayout>
</LinearLayout>

Your problem is you set ScrollView android:layout_height="0dp" and android:layout_weight="1"
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
and
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
so ScrollView takes nothing for hight
Edit
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
You can set android:layout_weight="1" as you want ratio between ScollView and RelativeLayout. Hare both will get half(1/2) of screen.

Related

Imageview not centered in parent - Android

I'm trying to position the blue icon precisely in the center of the card, but for some reason the icon goes up to the top of the card.
Can someone tell me what's wrong?
Thanks,
Here's a screenshot of my problem:
<GridView
android:id="#+id/documents_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:columnWidth="#dimen/document_grid_item_width"
android:gravity="center"
android:horizontalSpacing="0dp"
android:numColumns="auto_fit"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="48dp" />
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:background="#drawable/document_grid_item_bg">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
app:srcCompat="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:srcCompat="#drawable/draft_icon" />
</RelativeLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Date" />
</RelativeLayout>
I assume that in gridview item your parent is LinearLayout which can't be seen from your code snippet. If that's the case, in FrameLayout properties set the height to wrap_content
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:background="#drawable/document_grid_item_bg">
Given code snippet is working fine with LinearLayout as parent.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:focusable="true"
android:background="#color/colorGreen"
android:foreground="?android:selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
app:srcCompat="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/draft_icon"
android:layout_centerInParent="true" />
</RelativeLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Date" />
</RelativeLayout>
</LinearLayout>
1. Remove FrameLayout and add its attributes to child RelativeLayout.
2. Use attribute android:src instead of app:srcCompat to set image on ImageView.
Try this:
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:background="#fff">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/draft_icon" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="16 May 2017" />
</RelativeLayout>
</LinearLayout>
FYI, If you are using CardView as a container, then just put below LinearLayout inside your CardView.
OUTPUT:

Scroll View not working properly

I am trying to make a scroll view. I have a text field in my app and when I open the keyboard, the entire screen shifts up and I want to make it scroll so I could see what's going up there.
My scroll view has a text field and some image views to show up on the screen.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fillViewport="true"
android:id="#+id/scrollView2" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="570dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_marginTop="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Total Lives :"
android:id="#+id/textView12"
android:layout_marginTop="8dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/lifeImage1"
android:src="#drawable/full_brain_game" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/lifeImage2"
android:src="#drawable/full_brain_game" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/lifeImage3"
android:src="#drawable/full_brain_game" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/lifeImage4"
android:src="#drawable/full_brain_game" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/lifeImage5"
android:src="#drawable/full_brain_game" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/lifeImage6"
android:src="#drawable/full_brain_game" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textView7"
android:layout_marginLeft="150dp"
android:textColor="#color/red"
android:layout_marginTop="150dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/full_brain_game_1" />
</LinearLayout>
</ScrollView>
Change ScrollView child as RelativeLayout as follows and add Linear Layout inside RelativeLayout:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"
android:id="#+id/txtsignup"
android:text="Register Here"
android:textSize="30dp"
android:padding="10dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this, and keep adding your views in the Linear Layout.
first of all you need to Set your ScrollView's height and width to match_parent then the height of your linearLayout must be match_parent too. then everything gonna be okay.

How to align LinearLayout at bottom in a RelativeLayout?

I'm trying to get the LinearLayout to be aligned at the bottom of this RelativeLayout. I tried setting alignParentBottom="true", but then I can't even see the contents of the LinearLayout. Is there another way to accomplish what I need?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="90dp"
android:layout_height="200dp"
android:minHeight="200dp"
android:background="#color/colorPrimaryDark"
android:elevation="2dp"
android:gravity="center">
<TextView
android:id="#+id/textView_bookName"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:padding="10dp"
android:textSize="20dp"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/textView_bookAuthor"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="1dp"
android:text="Author"
android:textSize="10dp"
android:textColor="#color/white"
android:layout_below="#+id/textView_bookName"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/textView_bookAuthor"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_download_book"
android:text="#string/download"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_read_book"
android:text="Read"
android:visibility="gone"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/progressbar_book_download"
style="#android:style/Widget.ProgressBar.Horizontal"
android:progress="0"
android:visibility="gone"
/>
</LinearLayout>
</RelativeLayout>
Add to LinearLayout: android:layout_alignParentBottom="true"
eg.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_below="#+id/textView_bookAuthor">
[...]
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_height="100dp"
android:layout_width="wrap_content">
</LineaLayout>
Try using a LinearLayout that contains both layouts and setting them an android:layout_weight and android:layout_height="0dp".
Don't forget to set the ratio between the weights to one you'd like and setting the container's android:orientation to vertical.
BTW, for textSize you better use sp and not dp...
Please try below xml which I have modified. It will solve the issue. I have removed the android:layout_below="#+id/textView_bookAuthor" and added android:layout_alignParentBottom="true".
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="90dp"
android:layout_height="200dp"
android:minHeight="200dp"
android:background="#color/colorPrimaryDark"
android:elevation="2dp"
android:gravity="center">
<TextView
android:id="#+id/textView_bookName"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:padding="10dp"
android:textSize="20dp"
/>
<TextView
android:id="#+id/textView_bookAuthor"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="1dp"
android:text="Author"
android:textSize="10dp"
android:layout_below="#+id/textView_bookName"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_download_book"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_read_book"
android:text="Read"
android:visibility="gone"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/progressbar_book_download"
style="#android:style/Widget.ProgressBar.Horizontal"
android:progress="0"
android:visibility="gone"
/>
</LinearLayout>
</RelativeLayout>

Android XML - Unable to Prevent ImageView Overlap

I'm attempting to prevent two images from overlapping - and I though I'd be able to do so using two RelativeLayouts inside a LinearLayout - both set to wrap_content - however the two imageViews ( #+id/imageView1 - the boxart and #+id/background - the background) however they still seem to overlap.
Can someone spot what I may have done wrong in this implementation?
XML Source:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black" >
<RelativeLayout
android:id="#+id/rl_ListView2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#color/black" >
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:background="#drawable/boxart"
android:gravity="left"
android:paddingBottom="65dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/background"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:background="#drawable/background_faded"
android:gravity="right"
android:paddingBottom="65dp"
android:scaleType="fitXY" />
</RelativeLayout>
<ImageView
android:id="#+id/downloadbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="200dp"
android:paddingLeft="500dp"
android:src="#drawable/button_download" />
<ProgressBar
android:id="#+id/progressbar_Horizontal"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="585dp"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="440dp"
android:layout_marginRight="100dp"
android:max="100"
android:progressDrawable="#drawable/progressbar2" />
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:background="#drawable/timeline_bottom_android"
android:orientation="horizontal" >
<ImageView
android:id="#+id/backbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:src="#drawable/icon_back_arrow" />
<TextView
android:id="#+id/backButtonTxt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignRight="#+id/saveButton"
android:gravity="center_vertical"
android:text="Movies"
android:textSize="40sp" />
</LinearLayout>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/downloadbtn"
android:layout_below="#+id/downloadbtn"
android:layout_marginRight="207dp"
android:layout_marginTop="110dp" />
</RelativeLayout>
</LinearLayout>
Screenshot:
Instead of using Relative layout use a Linear layout with orientation horizontal and then use two Linear layouts with layout_weight=1 for each ImageView. It will divide your screen into two equal parts horizontally.
For example :-
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical" />
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical" />
</LinearLayout>
As per your given layout update your layout as follows:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/rl_ListView2"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="#drawable/boxart"
android:paddingBottom="65dp" />
</LinearLayout >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/background"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:background="#drawable/background_faded"
android:gravity="right"
android:paddingBottom="65dp"
android:scaleType="fitXY" />
</RelativeLayout>
<ImageView
android:id="#+id/downloadbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="200dp"
android:paddingLeft="500dp"
android:src="#drawable/button_download" />
<ProgressBar
android:id="#+id/progressbar_Horizontal"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="585dp"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="440dp"
android:layout_marginRight="100dp"
android:max="100"
android:progressDrawable="#drawable/progressbar2" />
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:background="#drawable/timeline_bottom_android"
android:orientation="horizontal" >
<ImageView
android:id="#+id/backbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:src="#drawable/icon_back_arrow" />
<TextView
android:id="#+id/backButtonTxt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignRight="#+id/saveButton"
android:gravity="center_vertical"
android:text="Movies"
android:textSize="40sp" />
</LinearLayout>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/downloadbtn"
android:layout_below="#+id/downloadbtn"
android:layout_marginRight="207dp"
android:layout_marginTop="110dp" />
</LinearLayout>
With regards to your particular situation, the 2 ImageViews causing problems are placed each in a RelativeLayout, which are also placed in a RelativeLayout. Views placed in a relative layout can overlap each other. So when you added the 2 children RelativeLayouts in the parent one, exactly this happened. To make one follow the other, you can add android:layout_toRightOf="#id/id_of_the_layout_you_want_on_the_left_of_this_one" to the second child.
Also, if you are willing to change your layout a bit, you could achieve this through weight and LinearLayout (note however that this will work only if the desired combined width of the 2 children is less than what the parent is willing to offer):
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
</LinearLayout>
</LinearLayout>

android layout center and bottom

In my layout i want to display two imagebuttons in the center and a my amountmeter below it on the bottom, all centered vertically, i have tried many ways but cant seem to find that perfect layout. all the component align vertically and center but it makes my amountmeter small and not full width of the screen.
How it should be
how it is now
updated code
current layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_cart" />
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_sell" />
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center|bottom"
android:padding="4dp" />
COPY PASTE BELOW CODE
<?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="horizontal" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/purchase"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/sell"
android:padding="4dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
AFTER THAT
android:background="#drawable/round_button"
android:src="#drawable/ic_sell"
android:background="#drawable/round_button"
android:src="#drawable/ic_cart"
PUT THIS LINE TO YOUR TWO IMAGE BUTTONS SURELY IT WILL WORK FOR YOU
One Linear layout is enough for this. Do not put your AmountMeterView into it's own LinearLayout.
Just make one Linear layout (vertical), and put all three elements in there. Gravity center_horizontal for all elements.
Try in this way hope this will help you
<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="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical" >
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp" />
</LinearLayout>
</LinearLayout>

Categories

Resources