Davis
Davis

Reputation: 215

Set 1 textview and 2 buttons independently in a Relativelayout

I have this XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

     <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/upperBar"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="@android:color/darker_gray"
      >

    <TextView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/txtForum"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:textSize="25dp"
            android:textColor="#255094"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:layout_alignParentLeft="true"
            android:maxLines="2"
            android:scrollbars="vertical"
            >
      </TextView>

    <ImageButton
          android:id="@+id/btnBrowser"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="5dp"
          android:layout_marginBottom="5dp"
          android:layout_alignParentRight="true"
          android:src="@drawable/icon_browser"
          android:contentDescription="Open Browser"
          >
    </ImageButton>

    <Button
          android:id="@+id/btnNewThread"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="NewThread"
          android:layout_marginTop="5dp"
          android:layout_marginBottom="5dp"
          android:layout_toLeftOf="@+id/btnBrowser">
    </Button>
</RelativeLayout>
   <ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:cacheColorHint="#00000000"
    android:padding="10dp"
    android:layout_below="@+id/upperBar">
    </ListView>
</LinearLayout>

And looks like this:

enter image description here

The problem is that, when the TextView is too long, it overlaps the buttons. I'd like to have those elements independently that the text is long. What should I add to my code?

Thank you.

Upvotes: 0

Views: 80

Answers (1)

android.fryo
android.fryo

Reputation: 1489

Add following code android:layout_toLeftOf="@+id/btnBrowser" for the text view.

Upvotes: 3

Related Questions