My xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:visibility="invisible">
<ImageButton
android:id="#+id/video_playback_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SeekBar
android:id="#+id/seekbar_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="#id/video_playback_pause" android:clickable=""/>
</RelativeLayout>
<VideoView
android:id="#+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" />
</RelativeLayout>
Now whe RelativeLayout and VideoView override.
the VideoView is show, and the RelativeLayout is hidden.
How to make the RelativeLayout on the top of VideoView?
Another problem is why the seekbar did not click?
I find that the priority of layout is decide by establish order?
But the problem of seekbar is still not resolve.
Try this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" >
<ImageButton
android:id="#+id/video_playback_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SeekBar
android:id="#+id/seekbar_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="#+id/video_playback_pause" android:clickable="true"/>
</RelativeLayout>
<VideoView
android:id="#+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</LinearLayout>
EDIT:
You can use the visibilty property as below
android:visibility="invisible" // invisible- just invisible the controls not the space
//gone - removes the allocated space too
//visible- shows the control
At run time also you can change
mylayout.setVisibilty(View.GONE)...
When it comes to your seekbar, this could be the possible answer: Set
android:clickable="true"
and in your java code, try putting an Event Listener. For Event Listeners, http://developer.android.com/guide/topics/ui/ui-events.html
When it comes to your layout, you can try using a Linear Layout and then nest a Relative Layout inside it. You might have to change your xml a bit.
Answer for the first part of question.
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true">
The inner relativeLayout's visibility is set to invisible.Remove it.
You have provided android:clickable="" for seekbar. May be thats why its not working.
Remove that and try.
Hope this will help you.
Related
I want the background picture not to be deformed, but everytime I try, ImageView appears in front of other UI elements.
I already tried with an image view android:src and scaleType=center,
and when I try with another layout, then I can't make the picture fit.
try settings scaleType=matrix, if that didnt help either then there is issues with intrinsic padding , i will post customImageview Then.
cheers!
Try this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="#string/xxxx"
android:src="#drawable/xxxx" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/xxxx"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/today"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="xxx"
android:textSize="xxsp" />
</RelativeLayout>
</LinearLayout>
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>
I have a ListView whit two taps underneath it, but i cant seem to figure out how to put an Image above the ListView. I have tried just putting an ImageView on top, but it wont do it?
This is how it looks now.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<ImageView
android:id="#drawable/frederiksberg"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"/>
</LinearLayout>
Try this code and run
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/add" android:layout_gravity="center_horizontal"/>
<ListView
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
It is working fine for me. Hope this helps you.
It is quite simple dude.
Take a Linear layout L1.
add one ImageView in L1 with Weight tag = 1
and add listview in L1 whose width and height must be fill parent.
make orientation of L1 as vertical..
let me know if any doubt.
here is solution make your parent layout as relative layout because it will provide you more flexiblity.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="122dp"
android:src="#drawable/ic_launcher" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1" >
</ListView>
</RelativeLayout>
hope it will work for you.. it is complete xml file i am posting for you try it.
I want a button to appear at fixed location all the time, in the footer of the UI ؟ ( always, if it has components above it or not )
Please take one Relative layout under your main layout . Set its height and width as fill parent and set its gravity as bottom and put any textview or any button you want in it.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bottom Gravity" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Without Gravity" />
</LinearLayout>
</FrameLayout>
It depends on the layout you are using.
On a RelativeLayout there is
android:layout_alignParentBottom="true"
On a LinearLayout, place it at the bottom and make sure to set the elements layout_weight properly.
Also, check the property
android:layout_gravity
and notice it's different than
android:gravity
Set android:layout_gravity="bottom". Hope this helps.
Put
android:layout_alignParentBottom="true"
in your relative layout.
if any one have two button you can just make this it orks for me
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom" >
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_yes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="Valider"/>
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="Annuler"/>
</LinearLayout>
</RelativeLayout>`
I have following in xml
I wanna put the second linear layout at the bottom of the screen.
How will i do?
I have set the property of second Relative layout to bottom but still not showing at bottom..
**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
<RelativeLayout android:id="#+id/RelativeLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</RelativeLayout>
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="bottom">
</RelativeLayout>
</LinearLayout>
**
Thanx in advance
I was searching for this a while too. My just found solution is to use the property:
android:layout_alignParentBottom="true"
instead of your existing android:layout_gravity="bottom"
This unfortunately with my layout only works when having an additional RelativeLayout as root layout and the rest added to it. Maybe this is not always the case, but with having a LinearLayout (even when told to use fill_parent) it only used the height all added elements needed and put my footer at the bottom of those.
I came to this solution, looking at this related question: How do I achieve the following result using RelativeLayout?
EDIT here because format in answer comment got lost:
Do you mean you can't re-write it or that it didn't work?
I had a vertical LinearLayout too and my new xml structure looks (without the layout size params etc.) sth. like this:
<RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout01">
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout02"
android:layout_below="#+id/RelativeLayout01">
</RelativeLayout>
<RelativeLayout
android:layout_below="#+id/RelativeLayout02"
android:layout_alignParentBottom="true">
</RelativeLayout>
</RelativeLayout>
The Layout you want at the bottom should have:
android:gravity = "bottom"
and its parent should have:
android:layout_height="fill_parent"
<Linearlayout android:layout_height="fill_parent"
android:orinationtation="vertical"
android:layout_width="fill_parent">
<RelativeLayout android:layout_height="0dp"
android:layout_width="fill_parent"
android:weight="1">
</RelativeLayout>
<RelativeLayout
android:layout_height="0dp"
android:layout_width="fill_parent"
android:weight="1"
>
</RelativeLayout>
</Linearlayout >
You should put a View before your last layout with weight 1, and it will put it to bottom. Like this:
<View android:id="#+id/emptySpace"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
Try using:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffb3e5fc"
android:id="#+id/linearLayout1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<Button
android:id="#+id/button1"
android:text="Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/centerPoint" />
<TextView
android:id="#+id/centerPoint"
android:text=""
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/button2"
android:text="Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/centerPoint" />
</RelativeLayout>
</LinearLayout>
It produces something that looks like this
For my it's work.
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#fff"
android:gravity="bottom"
app:layout_anchor="#+id/fab_inout"
app:layout_anchorGravity="bottom|center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dsfsdfasdf df" />
</RelativeLayout>