Bring content of FrameLayout to front - java

I have this activity layout where I have a header (RelativeLayout), content (FrameLayout) and a footer (RelativeLayout) all inside a LinearLayout (please refer to the attached screenshot below) :
The problem is that sometimes when content (which is actually a Fragment) is large enough, it gets clipped by the footer (e.g. in the attached image one can see that some button are being clipped). I have tried setting the background of footer layout to transparent (via xml and via code as well), calling the FrameLayout.bringToFront() method but nothing seems to work!
Pasted below is the layout xml I am using:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layoutMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical"
tools:context=".BatwaSelectLanguage" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" >
<ImageView
android:id="#+id/imBatwa"
android:layout_width="209dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:src="#drawable/batwa" />
<Spinner
android:id="#+id/spLang"
android:layout_width="140dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#000000"
android:prompt="#string/english" />
<TextView
android:id="#+id/tvSelectLanguage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_toLeftOf="#+id/spLang"
android:drawablePadding="30dp"
android:drawableRight="#drawable/line"
android:gravity="center"
android:text="#string/select_your_language"
android:textColor="#color/tvWhite"
android:textSize="#dimen/tvSizeSelectLang" />
</RelativeLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutFooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom" >
<ImageView
android:id="#+id/imNFC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="0dp"
android:layout_marginLeft="30dp"
android:contentDescription="#string/nfcimg"
android:src="#drawable/nfc" />
<ImageView
android:id="#+id/imNadra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="00dp"
android:layout_marginRight="10dp"
android:contentDescription="#string/nadra"
android:src="#drawable/nadralogo" />
</RelativeLayout>
</LinearLayout>

Related

text and buttons gets overlayed.....i want the buttons fixed at the bottom of the textview

I have uploaded a screenshot of the problem please check...
the text in the textview and the buttons gets over each other. I have used html for the text and scrollbar for it.....Please Help!!!!
Here's my code:
xml:
<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:background="#drawable/images"
tools:context="com.example.acer.aartisangrah.alaganraya">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
</ScrollView>
<Button
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="decrease"
android:text="Decrease" />
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="increase"
android:text="Increase" />
</RelativeLayout>
Here for the Text View I have used HTML
CODE:
tv=(TextView)findViewById(R.id.textView4);
tv.setTextSize((float) 18.0);
tv.setText(Html.fromHtml(getString(R.string.five)));
please note that the textsize of text in the text view can be increased or decreased....
It is because you have not specified the alignment order for your views.
Eg : You can use android:layout_above="#+id/btn" or android:layout_below="#+id/scrollbar for arranging views.
Make your code like this :
<LinearLayout 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:background="#drawable/images"
android:orientation="vertical"
tools:context="com.example.acer.aartisangrah.alaganraya">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="decrease"
android:text="Decrease" />
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="increase"
android:text="Increase" />
</RelativeLayout>
Just add these in your layout -
<ScrollView...
android:id=#+id/scroll_view>
...
<Button
android:id="#+id/b2"
android:layout_below=#id/scroll_view
.../>
<Button
android:id="#+id/b1"
android:layout_below=#id/scroll_view
android:layout_toRightof=#id/b1
.../>

Android Custom ViewGroup not rendering correctly

I have a ViewGroup that has the following xml layout:
<?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="wrap_content"
android:orientation="horizontal"
android:id="#+id/ticketBuy_viewLayout"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<ImageView
android:id="#+id/ticketBuy_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/ticketBuy_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/ticketBuy_icon"/>
<TextView
android:id="#+id/ticketBuy_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/ticketBuy_icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
Later, I put these Views into a ListView. And, well, don't really get the desired result.
What I want it to be is a small rectangular view with an image to the left, a title to the top right and the date to the bottom left. I am not posting the ListView xml because it does not have anything that would be of use (just a width and height set to match_parent) However, all I get is this (This ListView has about 8 elements):
I think you just messed up with the layout.
Try this layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ticketBuy_viewLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<ImageView
android:id="#+id/ticketBuy_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
/>
<TextView
android:id="#+id/ticketBuy_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/ticketBuy_icon"
/>
<TextView
android:id="#+id/ticketBuy_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/ticketBuy_name"
/>
</RelativeLayout>

Unable To Center Objects Within Two Relative Layouts

I'm attempting to split the UI for my horizontal layout into two halves each with it's own realative layout so I am able to center text and graphics within the two left and right halves of the screen. The problem is when I attmept to do so - the go button still ends up in the middle of the screen instead of centered on the right hand of the screen.
(If I can figure out how to center correctly I'm sure I'll be able to apply the same technique to the other elements to achieve the result I desire.
SOURCE:
<?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:layout_marginBottom="8sp"
android:layout_marginLeft="8sp"
android:layout_marginRight="8sp"
android:layout_marginTop="8sp"
android:background="#drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="24dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="#drawable/apn_app_logo" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/start2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/go_button"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/start_text2"
android:textColor="#000000"
android:textSize="18sp" />
<Button
android:id="#+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/apn_app_go_button" />
</RelativeLayout>
</RelativeLayout>
EDIT: (in response to Kuba's answer)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/background"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="24dp"
android:gravity="center"
android:scaleType="fitStart"
android:src="#drawable/apn_app_logo" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/background"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/apn_app_go_button"
android:gravity="center_horizontal" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/start_text2"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
Instead of Relative layout, I would recommend using LinearLayout.
<LinearLayout 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:orientation="horizontal"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#00dd00"
android:gravity="center"
>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#dd0000"
android:gravity="center_horizontal"
>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
In the inner LinearLayout you can either use android:gravity="center" to have its children centered vertically and horizontally. Or use use android:gravity="center_horizontal" to center in only horizontal way.
EDIT: Added the textview, which was discussed in the comments.
To have the textView appear underneath the button, you must change the orientation of the LinearLayout from horizontal to vertical. Please see the developer site .
The inner LinearLayout thus looks like this.
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:background="#dd0000"
android:gravity="center"
>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text here"
/>
</LinearLayout>
How can I use android:layout_below="#+id/go_button" in a linear layout?
You can't. These relationships only work in relative layout where you place views in relation to each other or the parent view. In linear layout items are stacked either vertically or horizontally.
Set android:gravity="center" in
<Button
android:id="#+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/apn_app_go_button" />
Maybe its work.

Custom ListView text always overlays each other

I have made a card layout for displaying a list of data. For some reason, no matter which properties I change for layout width, height, weight, etc, the text is always shown on top of other lines of text, as shown below.
What am I missing?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:background="#drawable/card_inset">
<RelativeLayout
android:id="#+id/eventDetails"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="70"
android:orientation="vertical" >
<TextView
android:id="#+id/eventTeams"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:textSize="17sp" />
<TextView
android:id="#+id/eventClickForMore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/eventTimeSection"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:orientation="vertical" >
<TextView
android:id="#+id/eventTime"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="22sp" />
<TextView
android:id="#+id/eventDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:textAlignment="center"
android:textSize="12sp" />
</RelativeLayout>
In your TextView called eventClickForMore, add the attribute android:layout_below="#+id/eventTeams".
And do the same thing for the TextView called eventDate which should be below eventTime
EDIT
I have updated the code, basically, you need to change the layout_height attribute of eventTeams and eventTimeSection to android:layout_height="wrap_content". match_parent made the TextView to take all the space vertically.
Also I think you could get rid of android:layout_alignParentBottom and android:layout_alignParentLeft in eventClickForMore and eventDate (not sure though, maybe the first update will be enough).
See my code below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:background="#drawable/card_inset">
<RelativeLayout
android:id="#+id/eventDetails"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="70"
android:orientation="vertical" >
<TextView
android:id="#+id/eventTeams"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17sp" />
<TextView
android:id="#+id/eventClickForMore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/eventTeams"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/eventTimeSection"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:orientation="vertical" >
<TextView
android:id="#+id/eventTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="22sp" />
<TextView
android:id="#+id/eventDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/eventTime"
android:gravity="center"
android:textAlignment="center"
android:textSize="12sp" />
</RelativeLayout>
You can use android:layout_below in your TextView with id #+id/eventClickForMore,
see
<TextView
android:id="#+id/eventClickForMore"
android:layout_width="fill_parent"
android:layout_below = "#id/eventTeams"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:textSize="14sp" />

Center vertically listview

I have a listview and a layout that is displayed in this way:
I wish that the items were also centered vertically. How can I do? this is the code
<?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" >
<TextView
android:id="#+ListView/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="24dp"
android:text="invisibile"
android:visibility="gone" />
<TextView
android:id="#+ListView2/x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="22dp"
android:text="TextView"
android:textSize="24dp" />
</RelativeLayout>
You have to create your own layout for your listview item. Soemthing
like this
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="#id/textItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Then, in your code, your going to have to do this
new ArrayAdapter(this, R.layout.yourRowItemLayoutHere,
R.id.textItem, functions);
Hop this is helpful to you
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Try this. it will place the text view inside relative layout both vertically and horizontally.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:id="#+id/some_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

Categories