Android alignment horizontal and vertical - android

hi i need to knw how to align button , text view and other things in ,
example when i add a button into the edge of the bottom of the screen bt when i turn screen into horizontal i want it to be in the same place.that means i want to be it in the edge of the bottom of the screen with same bottom padding.
How i could do this
this is the button code
<Button
android:id="#+id/btnEnter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_enter"
android:layout_marginTop="300dp"
android:layout_marginLeft="60dp"
android:textSize="45sp"
android:textColor="#000"
android:fontFamily="serif"
/>
i need when its turn into horizontal that button to be in the exact same place
thanks you
regards pran

add this for your button if it s in relative layout
android:layout_alignParentBottom="true"
otherwise
android:layout_gravity="bottom"

If Button is inside a RelativeLayout,
Use these properties for button:
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
If Button is inside a LinearLayout,
Use layout_gravity for button:
android:layout_gravity="right"
Hope it helps.

Related

Change button alignment of buttonA when buttonB is GONE

I have placed two buttons prev and next in a RelativeLayout. When I reach the last page of my app, I am disabling the next button using :
next.setVisibility(View.GONE);
The alignment of prev button is disrupted. I want it to be aligned to the centre of the RelativeLayout, as if there was only one button.
Here is my code :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="#+id/radgroup"
>
<Button
android:layout_marginTop="14dp"
android:layout_marginLeft="20dp"
android:text="#string/previous"
android:textAllCaps="false"
android:textSize="23dp"
android:layout_width="150dp"
android:layout_height="70dp"
android:id="#+id/prev"
android:onClick="viewPreviousQuestion"
/>
<Button
android:layout_marginTop="14dp"
android:layout_marginLeft="20dp"
android:text="#string/previous"
android:textAllCaps="false"
android:textSize="23dp"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_toRightOf="#+id/prev"
android:id="#+id/nxt"
android:onClick="viewNextQuestion"
/>
</RelativeLayout>
and the onClick event is
public void viewNextQuestion(View view) {
if(currqstn==lastqstn){
next.setVisibility(View.GONE);
}
}
Don't use a Relative Layout here,Use a Linear Layout Instead.
Since in a Relative layout Views are positioned with respect to one another, when you remove one view,it might disrupt other views that were positioned with respect to the deleted view.
EDIT
Use can use the following attributes for your views: weightSum, weight and padding.
Use Linear Layout to cover both the buttons Inside YOur main Relative Layout and and set
android:layout_weight="1"
android:layout_gravity="center_horizontal|center"
to your prev button.
When you using View.Gone its remove view place and other views are disturb
AND
when you using View.Invisible its always there just view is hidden and others views are not disturb.
use this...........
next.setVisibility(View.Invisible);
enjoy coding .....

How to let a TextView overlap over an ImageButton

I have a RelativeLayout and want to that my textfield will overlap over the given ImageButton. Currently the textfield is behind the imagebutton. I tried several options but did not find the correct one, any idea?
Thanks
<TextView
android:id="#+id/qrCode_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qrCode_hint"
android:textSize="20dp"
android:layout_alignBottom="#+id/btn_start_barcode"
android:layout_marginBottom="53dp"
/>
<ImageButton
android:id="#+id/btn_start_barcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/select_form"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:background="#ffffffff"
android:onClick="startBarcodeAction"
android:src="#drawable/barcode_bg" />
The RelativeLayout sets the Z-Index based on ordering of children.
So when you add a view below the others it will set Z-Index of that child higher than the last child.
Use a FrameLayout and put in the following order:
ImageButton
TextView
This will ensure that the TextView will be on top of the ImageButton.

How to make the buttons align bottom without any space below the buttons

How to align the buttons bottom of the screen.In the layout i have header below scrollview which contains many textviews and edittext and last is the 2 buttons that i want to place it bottom without any space besee at the bottom as i am able to align it bottom but ther is a small space between buttton and the screentween layout and buttons...
Do it in reverse way...
Open -Relative Layout
* Button1 - parent bottom true
* Button2 - Parent bottom true, Right of Button1, top align Button1, Bottom align Button1
* Header - Parent top true
* Scroll view - Below Header and Above Button1
close - Relative Layout
You can use android:layout_martin="0dp" to set the margin to zero, but with some Views this isn't enough as the 9Patch being used for the View background has a margin in it as well. In that case you need to both set the margin to zero, and use a different background 9patch.
http://developer.android.com/guide/developing/tools/draw9patch.html
make them in separate layout and and arrange at parent bottom
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/save_content"
android:layout_width="wrap_content"
android:text="save"
android:layout_marginRight="5dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="35dp"
android:layout_weight="1"/>
<Button
android:id="#+id/cancel_content"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="cancel"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="5dp"
android:textStyle="bold"
android:layout_weight="1"/>
</LinearLayout>

Android ImageButton not aligned with EditText and Button

I currently have this in my layout.xml
<EditText android:id="#+id/body" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:hint="Type to compose" />
<ImageButton android:id="#+id/attach"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="#drawable/attach_photo" />
<Button android:id="#+id/send" android:text="#string/send"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
Problem I'm facing is the top of the ImageButton is not aligned like the Button and EditText. The other 2 fill up the height nicely but the ImageButton seems to be sticking out upwards. Any ideas?
Try using a RelativeLayout. You can align views to the sides, top and bottom of the parent or any other view.
Using android:layout_alignParentTop="true" or similar.
There are loads of xml commands you can use in RelativeLayout.
You can also set the layout weight property on the children of your linear layout. You can set the weight of edittext, imagebutton and button which will align your components on screen.

View disappear while using relativelayout's "toLeftof"

I'm using Android's relativelayout, trying to make two buttons align side by side.
But, when I use layout_toLeftOf, my button02 suddenly disappear.
It's fine if I use layout_toRightof. Anyone knows why?
<Button
android:id="#+id/Button01"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#+id/Button01">
</Button>
<Button
android:id="#+id/Button02"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#+id/Button02"
android:layout_toLeftOf="#+id/Button01"
android:layout_alignTop="#+id/Button01"
android:layout_alignBottom="#+id/Button01"
>
</Button>
That's because the first one is aligned to the left; if you put the second button to the left of the first one, it will be outside the screen.
So, what if you change
android:layout_alignParentLeft="true"
to
android:layout_alignParentRight="true"
in the first button?
If you want Button2 to be left of Button1, why are you placing alignTop and alignBottom properties? Please remove that and see. Also remove alignParentLeft for Button1, if you want Button1 to be placed at the right side.

Categories

Resources