Displaying Button Above Image in Android - java

I am making an android application in which i have an ImageView and an Forward Arrow Button ,All i want is to display the button at the Right Center of the screen above the image.
Here is my code.....
<ImageView
android:id="#+id/ImageShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/postal_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/postal_address_hint"
android:inputType="textPostalAddress" />

Maybe you can try something like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ImageShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/YOUR_BUTTON_ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/ImageShow" />
</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>

Related

How to put button abover other and at the bottom android?

I would like to know how to put my three buttons at the bottom in the right order.
Actually the three buttons are aligned but at the top.
Here is my xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.example.siansa.MainActivity"
tools:ignore="MergeRootFrame">
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/blue"
android:text="#string/connexion"
android:textColor="#color/white" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/red"
android:layout_gravity="bottom"
android:text="#string/inscription"
android:textColor="#color/white" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/gold"
android:text="#string/guest"
android:layout_gravity="bottom"
android:textColor="#color/white" />
Did you try this in your XML?
android:layout_above="#+id/button"
android:layout_below="#+id/button"
android:layout_toLeftOf="#+id/button"
android:layout_toRightOf="#+id/button"
Edit:
Or try:
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"

xml layout isn't working for me

I have a lot of info to put on one xml page. Now i got what I want in the positions i want. However instead of fitting all my data on 3 key parts without running into each other, It keeps running into the next TextView. I was wondering how to have it auto adjust.
<?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" >
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/back" />
<TextView
android:id="#+id/makeup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginTop="97dp"
android:text="#string/part_section_2" />
<TextView
android:id="#+id/part_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginLeft="19dp"
android:layout_marginTop="38dp"
android:text="put text here for info" />
<TextView
android:id="#+id/part_safety"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_makeup"
android:layout_below="#+id/safety_title"
android:layout_marginTop="28dp"
android:text="put text here for safety" />
<TextView
android:id="#+id/info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:text="#string/part_section_1" />
<TextView
android:id="#+id/part_makeup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_info"
android:layout_below="#+id/makeup_title"
android:layout_marginTop="33dp"
android:text="put text here for makeup" />
<TextView
android:id="#+id/safety_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/part_makeup"
android:layout_marginTop="48dp"
android:text="#string/part_section_3" />
<TextView
android:id="#+id/part_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:textColor="#b70000"
android:textSize="16sp"
android:text="put text here for part title" />
</RelativeLayout>
would ScrollView work better? and how would switch this from this to ScrollView.
skin is 480x800
density is high(240)
Strings file - http://pastie.org/8534713
Changing to ScrollView (source):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="match_parent" >
<!-- your Button and TextView widgets -->
</RelativeLayout>
</ScrollView>
Edit:
As well as that, try changing your back button XML to this:
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/part_safety"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/back" />
The problem was android:layout_alignParentBottom="true". The bottom ended up not going to the bottom of the page like you had before. The ScrollView cut back on the bottom of the layout.

Resize scrollview only in android

I have an android layout made like this:
--------------
| IMAGE1 |
--------------
| SCROLLVIEW |
--------------
| IMAGE2 |
--------------
When the keyboard pops up to input text in the scrollview's edittext, it resizes the whole application. Is there any way to keep IMAGE2 at the bottom of the screen?
The layout of the application:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".SignupActivity" >
<ImageView
android:id="#+id/Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:src="#drawable/logo_1" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scaleType="centerCrop"
android:src="#drawable/wave_2" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Logo" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="286dp"
android:fadingEdge="none"
android:orientation="vertical"
android:paddingBottom="30dp" >
<EditText
android:id="#+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/name" />
<EditText
android:id="#+id/editSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/surname" />
<EditText
android:id="#+id/editCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/company" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<EditText
android:id="#+id/editUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/username" />
<EditText
android:id="#+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword" />
<EditText
android:id="#+id/editMail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/mail"
android:inputType="textEmailAddress" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<EditText
android:id="#+id/editAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/address" />
<EditText
android:id="#+id/editZipCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/zipcode" />
<EditText
android:id="#+id/editCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/city" />
<EditText
android:id="#+id/editCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/country" />
<EditText
android:id="#+id/editPhone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/phone" />
<EditText
android:id="#+id/editPhone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/mobilephone" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<Button
android:id="#+id/acceptButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="signup"
android:layout_gravity="center_horizontal"
android:text="#string/register" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Edit:
This is how actually the layout is. I want to keep the green wave image at the end of the page (under the keyboard) while still resizing the ScrollView to make it usable.
http://i.stack.imgur.com/ji1FB.png
http://i.stack.imgur.com/D4jcX.png
add this lines in your manifest in activity tag may be this works
<activity
android:name=".DemoActivity"
android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>
If you want your IMAGE2 stuck at the bottom of the screen, put below code inside your activity tag in manifest.xml
<activity
.
.
android:windowSoftInputMode="adjustPan" >
</activity>
EDIT:
Try to put below tag along with the above mentioned one
android:windowSoftInputMode="stateVisible|adjustResize"
Let me know if this one works for you.
The problem is that your Button is part of the ScrollView. You should pull your Button out of the ScrollView and into the parent RelativeLayout, changing the attributes as follows:
<Button
android:id="#+id/acceptButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" //keep it to the bottom of the layout
android:onClick="signup"
android:layout_gravity="center_horizontal"
android:text="#string/register" />
Then your ScrollView will also need a modification:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Logo"
android:layout_above="#+id/acceptButton" //make it stay above the button
>
And given that you are using android:windowSoftInputMode="adjustResize", this should give you the correct behavior.
EDIT: Wait, if you just want the background to stay positioned, try just setting that image as your windowBackground in your Activity theme. (e.g. add android:windowBackground="#drawable/my_background_image" to the theme that your Activity uses).

How to position a button in android XML?

Hey I have the code bellow for my buttons in XML and I would like the Anthem Button to be moved to the left hand side near the bottom corner and I will add a stop button in the bottom right, Could anyone advise me on how to do this?
XML:
<?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"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/country1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="45sp" />
<ImageView
android:id="#+id/ivFlag1"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:src="#drawable/sflag" />
<Button
android:id="#+id/bEdinburgh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ivFlag1"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
android:gravity="center"
android:text="#string/Edinburgh"
android:textSize="20sp" />
<Button
android:id="#+id/bGlasgow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bEdinburgh"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
android:gravity="center"
android:text="#string/Glasgow"
android:textSize="20sp" />
<Button
android:id="#+id/bAberdeen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bGlasgow"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
android:gravity="center"
android:text="#string/Aberdeen"
android:textSize="20sp" />
<Button
android:id="#+id/bAnthem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bAberdeen"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
android:background="#drawable/custom"
android:textSize="20sp" />
Set following attributes in the Anthem button
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
and following to the Stop button
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
In your Anthem Button, set android:layout_alignParentLeft or android:layout_alignParentRight to true will do the trick.

Changing imageview is drawing ontop on old image

I have a default image set as a src for an ImageView. Then i want to change this image. I do this:
ImageView imageView;
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.dude);
The result is that it only puts itself ontop of the old one, why could that be?
EDIT: added the xml-file:
<?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" >
<ImageButton
android:id="#+id/imageView"
android:layout_width="241dp"
android:layout_height="214dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/car"
android:src="#drawable/car" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button0"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clickclick"
android:textSize="30sp" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clickclick"
android:textSize="30sp" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clickclick"
android:textSize="30sp" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clickclick"
android:textSize="30sp" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="30sp" />
</LinearLayout>
<TextView
android:id="#+id/textViewGame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/instructionsGame"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
Change ImageView height/width to WRAP_CONTENT and remove android:background="#drawable/car" from ImageButton background :
<ImageView
android:id="#+id/imageView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/car" />

Categories