I have Linear Layout which acts as the parent of a Relative layout.The Relative layout consists of some buttons and stuff.I want to align the relative layout(panel containing buttons) at the bottom of the linear layout.The linear layout only consists of an ImageView and after that the relative layout should be aligned at the bottom.
But when i try to set android:layout_alignParentBottom="true" in the Relative Layout the IDE Prompts code is wrong.How can i achieve this please help
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:scaleType="fitStart"
android:src="#drawable/jellyfish" />
<RelativeLayout
android:layout_width="318dp"
android:layout_height="164dp"
android:layout_margin="5dp"
android:background="#drawable/backgrad"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="34dp"
android:onClick="clickme"
android:text="Button" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:layout_toLeftOf="#+id/button1"
android:onClick="textclick"
android:src="#drawable/text" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_centerHorizontal="true"
android:onClick="wmark"
android:text="Save" />
</RelativeLayout>
</LinearLayout>
Possible duplicate : How to achieve alignParentBottom="true" property in LinearLayout
When you set android:layout_alignParentBottom="true", you are trying to use methods of the LinearLayout. But LinearLayout DO NOT provide alignParentBottom.
The answer in the duplicate says to replace
android:layout_alignParentBottom="true"
by
android:gravity="bottom"
Add the following to your parent linear layout xml:
android:gravity="bottom"
I have answered another topic like this, solution is to put a View with weight 1 above your relative layout like this:
<View android:id="#+id/emptySpace"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
Try Enclosing your ImageView in a Linear Layout and add
android:layout_alignParentBottom="true"
in your Relative Layout.
Related
Been trying to do this for a while, and nothing is working.
I'm trying to vertical and horizontal center a linear layout inside a relative layout.
The point is to get two text-views perfectly centered inside the relative layout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="350dp"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:textColor="#ff0fff"
android:background="#ffffff"
android:textSize="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:textColor="#ff0fff"
android:background="#ffffff"
android:textSize="20dp"
/>
</LinearLayout>
</RelativeLayout>
Any help is appreciated.
set attribute centerInParent to true to center Linear Layout in Relative Layout and gravity to center TextView in your LinearLayout
<LinearLayout
android:layout_width="350dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:gravity="center">
I have two relative layout inside linear layout. I want the first relative layout left align and the second relative layout right align. I set the following line in the second relative layout but it is not working.
android:layout_alignParentRight="true"
and my full xml file goes here.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<RelativeLayout
android:id="#+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="45"
android:background="#drawable/listview">
<ImageView
android:id="#+id/leftPanelImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:src="#drawable/sports"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="left panel"
android:layout_marginTop="5dp"
android:layout_below="#id/leftPanelImage"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="45"
android:background="#drawable/listview"
android:layout_alignParentRight="true"
>
<ImageView
android:id="#+id/rightPanelImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:src="#drawable/sports"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="right panel"
android:layout_marginTop="5dp"
android:layout_below="#id/rightPanelImage"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
My current code gives an output like this. Second layout start after first layout. I want it to start from the right from parent.
So my question is how can I set the second relative layout right align.
Thank you.
android:layout_alignParentRight is for children within relative layout. Since your relative layouts are children for linear layout, try using
android:layout_gravity="left"
and
android:layout_gravity="right"
Your layout seems to be very overkill, using LinearLayout weights and RelativeLayout for such a simple layout is not necesseary. Also both these methods requiere double measurement which is slower. I would suggest to always use as few elements as possible – for your layout try something like
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
android:weightSum="100">
<TextView
android:layout_width="0dp"
android:layout_weight="45"
android:layout_height="wrap_content"
android:drawableTop="#drawable/sports"
android:drawablePadding="5dp"
android:text="left panel"/>
<View
android:layout_width="0dp"
android:layout_weight="10"
android:layout_height="match_parent"/>
<TextView
android:layout_width="0dp"
android:layout_weight="45"
android:layout_height="wrap_content"
android:drawableTop="#drawable/listview"
android:drawablePadding="5dp"
android:text="right panel"/>
</LinearLayout>
android:layout_alignParentRight and android:layout_alignParentLeft are used to align a child right or left inside a relative layout. Of course, it won't work with LinearLayout as parent. You can change your parent layout to RelativeLayout.
android:layout_alignParentRight attribute is meant to work in children of Relative Layouts. You are using in in a child of a Linear Layout.
You can set it to the childs of the RelativeLayout OR use on the parent view android:gravity="right".
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="45"
android:background="#drawable/listview">
<ImageView
android:id="#+id/rightPanelImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:src="#drawable/sports"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="right panel"
android:layout_marginTop="5dp"
android:layout_below="#id/rightPanelImage"/>
</RelativeLayout>
I have a relative layout, and inside it i place 3 items, 2 imageviews and one scrollview.
My layout is like this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:baselineAligned="true"
android:background="#drawable/background">
<RelativeLayout
android:id="#+id/logosLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_margin="16dp"
android:gravity="center">
<!-- An image will be placed here -->
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="#33ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/up" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="8dp"
android:fadingEdgeLength="32dp"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/hotelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="#drawable/button_background"
android:contentDescription="#string/hotelBtnDesc"
android:gravity="center"
android:src="#drawable/icon1" />
<TextView
android:id="#+id/hotelBtnDescTxtVw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="#string/hotelBtnDesc"
android:textColor="#ffffff"
android:textSize="14sp" />
<!-- more scrollview items -->
</LinearLayout>
</ScrollView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/down" />
</RelativeLayout>
</LinearLayout>
The above code produces the view shown here:
You may note that the arrows are not aligned in the center, but are slightly moved to the right. Why is that, and how can I fix it ? Note that i have already used android:layout_centerHorizontal="true" to my imageviews.
Thank you in advance
Its problem with your
android:layout_margin="8dp"
remove it from both scrollview and imageView
and pass it to RelativeLayout direct.
or add
android:layout_marginTop="8dip"
android:layout_marginBottom="8dip"
in your RelativeLayout.
and pass
android:layout_centerHorizontal="true"
to your scrollview
they are aligned to the center if you put the marginRight into consideration, try adding android:layout_margin="8dp" to the arrows.
u need to set image view that is under the Relative layout set this image view width fill parent.
Try removing android:layout_weight="1" from your RelativeLayout and see if it works.
In your LinearLayout, the attribute android:orientation="horizontal" causing your display to be aligned horizontaly. Therefore your RelativeLayout is in center but since its shared with another layout thats why you cant note the difference. If you completely remove the first RelativeLayout (the one with id logosLayout) then i hope you'll see the second layout in center.
So, first you need to define the hierarchy of layout you require and then adjust your views accordingly.
It seems problem with your android:layout_margin="8dp" for your scrollview only and pass it to RelativeLayout direct but instead of using margin use padding = "8dp".
How do I stop my view from filling the entire screen and not showing my buttons at the bottom of the screen?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.vig.comix.ImageZoomView
android:id="#+id/zoomview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentTop="true" />
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="#+id/zoomview" android:layout_alignParentBottom="true">
<ImageButton android:id="#+id/btnPrev"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#android:drawable/ic_media_rew"
android:background="#null"
android:layout_weight="1"
android:width="0px" />
<ImageButton android:id="#+id/btnNext"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#android:drawable/ic_media_ff"
android:background="#null"
android:layout_weight="1"
android:width="0px" />
<ImageButton android:id="#+id/btnMove"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#android:drawable/btn_star"
android:background="#null"
android:layout_weight="1"
android:width="0px" />
<ImageButton android:id="#+id/btnDelete"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#android:drawable/ic_menu_delete"
android:background="#null"
android:layout_weight="1"
android:width="0px" />
</LinearLayout>
</RelativeLayout>
When I change my code and put the buttons at the top, it works fine. I have tried relative layouts, linear layouts, lauout weights, ...
What am I doing wrong?
RelativeLayout can be tricky to work with. I try to stick with FrameLayout and LinearLayout. Here is a sketch of the layout I would use in your case:
<LinearLayout orientation="vertical">
<ImageZoomView layout_weight="1" layout_height="wrap_content">
<LinearLayout orientation="horizontal" layout_height="wrap_content">
... buttons ...
</LinearLayout>
</LinearLayout>
Heights and widths are fill_parent when not mentioned. The layout_weight attribute on the ImageZoomView will cause it to expand as far as it can without squishing your bottom buttons.
Instead of putting android:layout_below in your LinearLayout. Try removing that and put
android:layout_above="#+id/myLinearLayout"
inside your ImageZoomView. Of course giving your LinearLayout the same id.
Perhaps the layout_weight is causing issues? Also it doesn't seem like you're give the items an object to be positioned relative to?
Change this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
to this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
How to set footer in android on each page
I have used:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/mcolor"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="fill">
<ImageButton android:id="#+id/iconbtn"
android:layout_height="wrap_content"
android:src="#drawable/all_icon_138"
android:layout_marginRight="4px"
android:layout_gravity="fill"
android:clickable="true"
android:layout_width="wrap_content"
android:background="#color/mcolor"
android:layout_marginLeft="60px"
android:layout_marginTop="12px" android:saveEnabled="true">
</ImageButton>
<TextView android:text="#+id/TextView01"
android:id="#+id/label"
android:textColor="#color/mbcolor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scrollbars="vertical"
android:layout_marginBottom="30px"
android:layout_marginTop="30px"
android:textSize="12px"
android:layout_marginRight="30px"
android:layout_marginLeft="130px"></TextView>
<LinearLayout android:layout_marginTop="50dip"
android:gravity="bottom"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true">
<ImageButton android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/newfox_footer_320"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false"
android:layout_alignParentLeft="false" android:layout_marginLeft="190px" android:layout_marginRight="2px">
</ImageButton></LinearLayout>
</RelativeLayout>
It is showing 6 images of footer after each TextView.
How do I set it?
its is not clear what do you exactly want but i assume you want a footer in a layout.
use a framelayout as you main layout with
width = fillparent
height = fillparent
take another framelayout set the gravity to bottom.
add views to this framelayout.
this is your footer.
Make the root view of your xml Layout a RelativeLayout.
Then the view you want as footer, or his parent (the one who is direct child of the root view element: RelativeLayout) needs to have this attribute:
android:layout_alignParentBottom="true"
You've used LinearLayout for footer, so you can check out stackoverflow: footer for linear layout in android