0

I have defined the following layout for the title bar in my android app.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    android:id = "@+id/CustomTitleRelativeLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/titleTvCenter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="Center" />

    <Button
        android:id="@+id/clearcachebutton"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="@string/clear_cache_button_text" />

</RelativeLayout>

Here my button is not getting displayed completely. Can anyone help me where I'm going wrong.

The display is as follows:

enter image description here

In the title bar , as you can see the button Text is not shown correctly.

2 Answers 2

1

Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/CustomTitleRelativeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Button" />

    <TextView
        android:id="@+id/titleTvCenter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Center" />

</RelativeLayout>
Sign up to request clarification or add additional context in comments.

2 Comments

I'm still having the same problem.
Please add code of all layout, but not only top panel(Title Bar).
1

The problem is that your Button uses fill_parent for layout height. When its parent is set to wrap_content, it will wrap only what is necessary. Since the button simply matches that instead of insisting it wraps its own content, it gets chopped.

Just change the Button height to wrap_content and you'll be set.

I assume this is what Artyom was saying with that answer, but it's not very clear.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.