2017-02-12 84 views
1

enter image description here我有以下佈局。我需要的是一個位於左側角落的文本框,稍後我會插入一個計數器,以顯示地圖將在幾秒鐘後刷新。Android textview邊框覆蓋頂部地圖的大面積

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

這裏是border.xml。現在的問題,我只是想邊界附近的單詞,但在這裏它邊界整個頂部區域。我想限制在單詞之內。

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 
    <stroke 
     android:width="2dp" 
     android:color="#0288D1" /> 
</shape> 
+0

「我只想邊境周圍這個詞「意味着什麼?您正在將它應用於textView而不是用於單詞 –

+0

的單詞。但是,當我應用它時,它獲得整個文本視圖,它看起來很難看 – user5313398

+0

然後扭曲視圖或發佈預期的輸出 –

回答

1

你的TextView layout_width="match_parent"將採取全寬,它可以和你申請的背景觀點不是裏面的文字,所以你說的話是對的。

經你的看法,如果你想申請的背景僅文本週圍

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

參見:What's the difference between fill_parent and wrap_content?

對於你的第二個問題:

<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> 
+0

@charus如果我希望textview的背景被稱爲白色或其他顏色並且圍繞它的邊框? – user5313398

+0

@ user5313398我會更新我的答案 –

+0

@Charus目前我正在使用形狀,所以我必須做出什麼改變,以便背景不是透明的,而是一種特定的顏色? – user5313398