Can I overlap the WebView with an ImageButton? - android

What I want to create should look like this :
I want it like this because I want the button to cover a part of the content of the webview making it unreachable for the user.

You can do it using FrameLayout as follows...
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Button" />
</FrameLayout>

Yes You can do.for that purpose you have to use relative layout.first you have add webview,then add image button and set gravity bottom to image button.i think this can help you.
<?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" >
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#android:color/darker_gray"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

Related

Background image for a button in android

I am trying to add a background image for a button and it is working, but not as I expected.
1st picture (without background)
2nd picture (with background)
I would like the background to cover only the button. In other words, the image should have the same form as the 2 buttons from above (I'm talking about the round corners and a bit smaller size).
Here is the xml of the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main" tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button
android:onClick="playerStats"
android:text="#string/plStats"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button
android:text="#string/comp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button
android:background="#drawable/calendar"
android:text="#string/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
its easy to do that
you should use ImageButton and remove those Buttons for example
<ImageButton
android:src="#drawable/calendar"
android:text="#string/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
also if you want to remove the background of that button you can use :
android:background="#null"
Replace your layout with these layout...It can be helpfil for you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main" tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout android:layout_weight="1" android:layout_height="match_parent" android:layout_width="match_parent">
<Button
android:onClick="playerStats"
android:text="#string/plStats"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<View ////I HAVE ADDED VIEW WHICH IS TRASNPARENT TO SEPRATE THE BUTTONS
android:layout_width="fill_parent"
android:layout_height="10dp"
android:background="#android:color/transparent" >
</View>
<LinearLayout android:layout_weight="1" android:layout_height="match_parent" android:layout_width="match_parent">
<Button
android:text="#string/comp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<View ////I HAVE ADDED VIEW WHICH IS TRASNPARENT TO SEPRATE THE BUTTONS
android:layout_width="fill_parent"
android:layout_height="10dp"
android:background="#android:color/transparent" >
</View>
<LinearLayout android:layout_weight="1" android:layout_height="match_parent" android:layout_width="match_parent">
<Button
android:background="#drawable/calendar"
android:text="#string/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<View ////I HAVE ADDED VIEW WHICH IS TRASNPARENT TO SEPRATE THE BUTTONS
android:layout_width="fill_parent"
android:layout_height="10dp"
android:background="#android:color/transparent" >
</View>
The simplest solution is: You need to edit your image background (make it a little smaller and have corner) - it can be done easily by using Photoshop
Than use 9-patch tool for make 9-patch image (9-patch images can automatically resize to accommodate the contents of the view and the size of the screen)
The "without background" button is actually displaying it default background, so setting new background will override that corner-rounded-gray thing...
Check this question.
I recommend using ImageButton with android:src instead.

Unable to display the ImageView in FrameLayout (Android)

I had made a simple camera app and was thinking about customizing the view. Currently, I've been stuck with a problem with the ImageView not being able to be displayed on the top of the framelayout. Is there something wrong with the xml code below ? Or should I set some parameter in the code ? All I want to do is to display the Imageview above the framelayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_vertical">
<ImageView
android:id="#+id/button_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/shot_dot_icn" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
Try this layout, I am not sure if I understand your requirement though.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="#+id/button_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/shot_dot_icn" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
I solved the problem with the script below. All I had to do was to set the bringToFront() to the ImageView to set the view on top of the Framelayout.
ImageView captureButton = (ImageView) findViewById(R.id.button_capture);
captureButton.bringToFront();

Android LinearLayout with Button and FrameLayout using the Maximum Height

I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>

How to anchor buttons at the bottom of the layout?

I'd like the OK / Cancel buttons to be anchored at the bottom (even when there's more items on the list that can be shown on the screen). Here's what it currently looks like:
The buttons are on the top, not on the bottom.
The layout that contains the buttons:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="true"
android:id="#+id/buttons_layout">
<TableRow>
<Button
android:id="#+id/btnOK"
android:background="#color/pomegranate"
android:text="OK"
android:layout_gravity="fill_horizontal"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnCancel"
android:background="#color/wet_asphalt"
android:text="Cancel"
android:layout_weight="1"
android:layout_gravity="fill_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
The composite layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/options_list"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</ListView>
<include layout="#id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="match_parent"
android:layout_below="#id/options_list"/>
</RelativeLayout>
I followed the guidelines I read on http://developer.android.com/guide/topics/ui/layout/relative.html
I tried this answer - https://stackoverflow.com/a/6285438/168719 - it hasn't helped me.
I suspected that it might not work because the list view doesn't "know" how tall it is, so the button layout doesn't know where to place itself, either. But I ruled it out by setting the ListView height to an arbitrary value like 100dp. The buttons are still superimposed over it.
I fiddled with all the layout attributes, but I can't get it to work.
Apart from the solution, I would also like to know why mine doesn't work...
the layout should be something like this :
<?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">
<ListView android:id="#+id/options_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layout_buttons" >
</ListView>
<include android:id="#+id/layout_buttons"
layout="#id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="wrap_parent"
android:layout_width="wrap_content"/>
</RelativeLayout>
you can use tab to do it
you can see this tutorial
Android Tab Layout Tutorial
you could try using it this way
<relativelayout1>
<relativelayout2 specify layout below listview with id="list">
<button1>
<button2>
</relativelayout2>
<listview id="list">
</listview>
</relativelayout1>
so this will ensure no matter how long your list is you always get the buttons below your list. so you can have a scrolling list and a static buttons below the list
try this. Put the include tag inside another RelativeLayout, then be sure ListView is above the new RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/buttonsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<include
android:id="#+id/buttons"
android:layout_width="wrap_content"
layout="#layout/buttons_layout" />
</RelativeLayout>
<ListView
android:id="#+id/options_list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#id/buttonsContent" >
</ListView>
</RelativeLayout>
Try like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layout_buttons"
android:orientation="vertical" >
<ListView android:id="#+id/options_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
<include android:id="#+id/layout_buttons"
layout="#id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="wrap_parent"
android:layout_width="wrap_content"/>
</RelativeLayout>

Set footer colour in xml

I am using the ViewPageIndicator library in my app. I know I can change the footer colour by using something like .setFooterColor(Color.Red) in my code. My question was if I can set this in xml instead as I would like to to all the styling in xml.
Below is the xml code
<com.viewpagerindicator.TitlePageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
What attribute do I need to set here to change the footer color? Thanks.
Here is an example for doing that:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/tn.mkh.example.android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/fragmentContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone" />
<com.viewpagerindicator.TitlePageIndicator
android:id="#+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
app:footerColor="#848484"
app:selectedBold="true"
app:selectedColor="#color/vpi_color_custom" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Good luck

Categories

Resources