1

enter image description hereI have the following layout. What I need is a textbox at left hand corner which later I will plug in a counter to show the map is going to refresh after certain seconds.

<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" >

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/map"
    tools:context="com.example.ns.appversion1.MapActivityFragment1"
    android:name="com.google.android.gms.maps.SupportMapFragment"/>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="96dip"
            android:orientation="vertical"
            android:weightSum="2" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="left"
                android:background="@drawable/border"
                android:text="Refreshing 1"
                android:textColor="#000"
                android:textSize="12sp" />


        </LinearLayout>
    </FrameLayout>
 </RelativeLayout>

Here is the border.xml. The problem now I just want the border to around the word but here it border the whole top area. I want to limit just within the words.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <stroke
        android:width="2dp"
        android:color="#0288D1" />
</shape>
Charuක
  • 12,953
  • 5
  • 50
  • 88
user5313398
  • 713
  • 3
  • 9
  • 28

1 Answers1

1

Your TextView layout_width="match_parent" will take the full width that it can take and you are applying background to the view not for the text inside it so what you are saying is right.

Warp your view if you want to apply background only around the text

   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:background="@drawable/border"
        android:text="Refreshing 1"
        android:textColor="#000"
        android:textSize="12sp" />

Refer : What's the difference between fill_parent and wrap_content?

For your second question :

  <layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="#1bd4f6" /> <-- here
            <stroke
                android:width="2dp"
                android:color="#0288D1" />
        </shape>
    </item>

</layer-list>
Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88