Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FrameLayout overlaps TextView

 
Lou Cabron
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using a RelativeLayout for a very simple app which consists of a textView at the top and a FrameLayout at the bottom. But the FrameLayout keeps overlapping the TextView on small-screen devices (like a cellphone). Here's some of the things I've tried that *haven't* worked to resolve the problem. (I tried Weight="1", but it's a relativeLayout, so Eclipse gives an error message. And I tried android:layout_below="@id/theText" but the contents of the FrameLayout then decide to vertically align themselves at the *top* of the FrameLayout...)


<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"
tools:context=".MainActivity"
android:id="@+id/myLayout"
android:clickable="true"
androidnClick="myMethod"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:id="@+id/theText"
android:textSize="34sp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:shadowColor="@color/white"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"

/>


<FrameLayout
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></FrameLayout>
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key is, you layout the frame's alignment to the bottom of the screen and you make it below the text area.

Now the Frame will always take the space from just below the text to the bottom of the screen. The problem is that your content is probably bigger than that, which is why your bottom-aligned frame overlapped the text to begin with. Using the above mechanism will essentially ignore the frame's 'wrap_content' height to make it align appropriately. So to get the content on small screens you will need to wrap the FrameLayout into a ScrollView.

This with an AnalogClock that makes the Frame not fit on small screens. See the result image below. (Note the area with the Clock should scroll but that isn't shown in the static image). Also note that I only have one thing inside my FrameLayout. If that is your case, I would replace the FrameLayout with the ScrollView instead of wrapping it in the ScrollView.
TextAndFrame with Clock.png
[Thumbnail for TextAndFrame with Clock.png]
Layout for Text on top of a frame with a clock in it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic