put a button in frameLayaout - android

I have a small application with the camera and I have a device which is not a problem but if I can change the app will improve much aesthetically.
I put the xml code of the activity:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/layout">
<FrameLayout
android:id="#+id/preview"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="0dip">
</FrameLayout>
<Button
android:id="#+id/buttonClick"
android:layout_width="109dp"
android:layout_height="105dp"
android:layout_gravity="center"
android:background="#drawable/obutrador2" >
</Button>
</LinearLayout>
When I run the application, there is a white stripe along the entire height of the screen occupied by the button. How I can fix this? It would make the button appear above the image that the camera is capturing, as the app that has the default phone.
The problem is how to position the frame layout so that it fills the screen and center the button at the bottom. If I make the FrameLayout full-screen, the button disappears.
I leave a link to a photo of what happens:
https://www.dropbox.com/s/jbns8jddtwxjhdp/IMAG0348.jpg

I think you should define Button inside the FrameLayout like this.
You can make FrameLayout as parent layout and you can place button where ever you want
<FrameLayout
android:id="#+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/buttonClick"
android:layout_width="109dp"
android:layout_height="105dp"
android:layout_gravity="center"
android:background="#drawable/obutrador2" >
</Button>
</FrameLayout>
Hope This should be work for you...Thanks

Related

Align a button below the bottom of the screen

Currently my code places a button at the bottom of the screen:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|bottom">
<ImageButton
android:id="#+id/button1"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_centerInParent="true"
android:gravity="center"
android:src="#drawable/main_button"
/>
</LinearLayout>
</RelativeLayout>
However, I wish to align it slightly below the bottom of the screen, so a small part of the button is clipped off (Say, 20%). Ultimately, my end result is that when I tap and drag the button up, it will move up and reveal the entire button, but before that, the bottom part of it is clipped.
There are many questions on how to align a button to the bottom of a screen, but I can't seem to find any that aligns it to below the bottom of the screen.
Is there any way to do so, or am I not using the correct search terms?
EDIT: From the answers, I tried android:translationY="20dp" and it did not work, but I tried android:layout_marginBottom="-20dp" and it worked for me.
You can add android:translationY="Xdp" to your button to move it down by X dp.
Alternatively you can create two LinearLayouts. One to fill the screen and hold other components and another that contains the button. You can then add android:layout_below="#id/layout0" and android:margin_top="Xdp" to control how far below the screen the layout with the button should be.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true">
</LinearLayout android:id="#+id/layout0"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="#id/layout0"
android:margin_top="Xdp"
android:gravity="center|bottom">
<ImageButton
android:id="#+id/button1"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_centerInParent="true"
android:gravity="center"
android:src="#drawable/main_button"/>
</LinearLayout>
</RelativeLayout>
You can translate the button:
android:translationY="20dp"
in your xml, that's moves the view 20 dp's down.

dynamically size image of an imagebutton in Android

I have a problem sizing a picture into a imagebutton. Actually my button holds a image that is too large and I can see only a part of my picture on the imagebutton.
I have a activity with a layout which defines a webview with a button at the bottom in a sizerelation of 1/8. I mean the webview takes 8 parts of the screen and the button 1 part.
My layout looks simplified like this :
WebView
...
...
android:layout_weight="8" /
LinearLayout
...
...
android:layout_weight="1"
<ImageButton
...
android:layout_weight="1"/
/LinearLayout
because of the weight definitions, I do not know the pixelsize of my button and I can't size my picture into the button correctly.
How can I size my image to the button correctly ? Or how can I manager that my button is sized correctly into my button ?
Hopefully you are get help from below my codes. such as
<?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="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#000"
android:layout_weight="7" />
<Button
android:id="#+id/bLogin"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ff0000"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Now you can modify dependable on you wish. Best of luck!

Android layout design: image above form above button. When the keyboard appears my layout is screwed

In my application I want to have a layout like this:
I did it with a Relative Layout holding an ImageView, TableLayout and a Button. The problem is that when I open the keyboard to modify a EditText the keyboard is on top of the EditText, so the user can't see what he is writing. I want the layout to be like this when the keyboard is shown:
The user should be able to scroll up the view to see the whole image while the keyboard is shown, even if he doesn't see the EditText then, because he wants to copy some data of the image into the EditTexts. I tried to do it like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/buttonEditStop"
android:padding="10dip" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/stopImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:clickable="true"
android:contentDescription="#string/entry_img"
android:onClick="ImageClick" />
<TableLayout
android:id="#+id/formLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/stopImg"
android:layout_marginRight="10dp" >
...
</TableLayout>
</RelativeLayout>
</ScrollView>
<ImageButton
android:id="#+id/buttonEditStop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/edit_stop"
android:onClick="EditButtonClicked"
android:src="#drawable/ic_menu_edit" />
Using this code my whole layout is screwed. I see the form on top of the image, followed by a ImageButton with the image that should be seen in the imageView.
Anyone knows how I can get a layout like the one I want?
Thanks!
To avoid the EditText to be overlapped I had to use
android:windowSoftInputMode="adjustPan"
in my manifest.

Android issue with a centered bitmap displaying weirdly

I have an issue with an image in my application.
I would like to have a header image that would take all the width of my application.
To do that, I created an extremely wide picture with the main object in the center,
then center that bitmap in my layout.
Using that code:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/header"
android:gravity="center_horizontal|bottom" />
and that layout definition:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#ffffff"
android:layout_gravity="center_horizontal" >
<LinearLayout
android:id="#+id/accueil_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:layout_gravity="center_horizontal" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:background="#drawable/bitmap_header"
android:layout_weight="1">
<TextView
android:id="#+id/allure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txt_allure"
/>
</FrameLayout>
<TextView
android:id="#+id/slogan"
android:text="#string/txt_slogan"
/>
that code this is well working at the first execution.
as you can see here : http://imagebin.org/index.php?mode=image&id=169619
if I call an other Intent and then go back to that one, it's still displayed normally.
But if I call another Intent to the same activity,
the second instance of this activity is displayed weirdly.
as here : http://imagebin.org/index.php?mode=image&id=169620
As anyone an idea, on how I could resolve this?
I think that has to do something with TextView under FrameLayout, because it is not displayed on second picutre. Maybe change FrameLayout to RelativeLayout or LinearLayout and see what happens.

Android layout issue with buttons below WebView

So I have a webview I'd like to display as a dialog. I'd like the webview to fill the entire screen, except for a button below it that I'd like to stay at the bottom of the dialog regardless of how much content is in the webview. Currently my webview fills up the dialog just enough to push the button off the screen. I'm sure this is something pretty easy but for the life of me, I haven't been able to find the magical combination of layouts, views and attribute values to get it to play nice. Just to be clear, I've gotten it so the button floats over the webview but I'd like the webview to stop just above the button and scroll, if that makes sense.
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:text="Ok"
android:id="#+id/btnOk"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
You will want to use android:layout_above="#+id/btnOk" for your webview, and do fill_parent for width and height of the webview.
However, it is important to note, that in 1.5 and below, RelativeLayout views need to be specified in order in your xml to be recognized correctly.. in other words, you have to have your Button first, then the WebView, since the WebView will reference the button. I think this has been changed in 1.6 or 2.0, but I am not positive which.
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="Ok"
android:id="#+id/btnOk"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<WebView android:id="#+id/webview"
android:layout_above="#+id/btnOk"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>

Categories

Resources