2016-04-13 26 views
0

有沒有一種方法可以將文本屬性放在android:drawableBottom屬性上方。這是我嘗試android按鈕:android:text上面的android:drawableBottom的按鈕

這是下面的代碼的屏幕截圖

enter image description here

<Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/snap" 
      android:textColor="#FFFFFF" 
      android:background="#00FFFFFF" 
      android:id="@+id/shutterButton" 
      android:layout_weight="1" 
      android:padding="5px" 
      android:text="SNAP"></Button> 

I want to place the SCAN Text on top of the image

EDITTED 這是顯示按鈕的組是如何被放置在的LinearLayout在水平方向上

<LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#338FD8D8" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:orientation="horizontal" 
       android:paddingBottom="10px" 
       android:paddingTop="10px"> 
<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableBottom="@drawable/snap" 
     android:textColor="#FFFFFF" 
     android:background="#00FFFFFF" 
     android:id="@+id/shutterButton" 
     android:layout_weight="1" 
     android:padding="5px" 
     android:text="SNAP"></Button> 

       <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableTop="@drawable/xxx" 
     android:textColor="#FFFFFF" 
     android:background="#00FFFFFF" 
     android:id="@+id/xxx" 
     android:layout_weight="1" 
     android:padding="5px" 
     android:text="xxx"></Button> 

       <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableTop="@drawable/xxx" 
     android:textColor="#FFFFFF" 
     android:background="#00FFFFFF" 
     android:id="@+id/xxx" 
     android:layout_weight="1" 
     android:padding="5px" 
     android:text="xxx"></Button> 


     </LinearLayout> 

上述代碼不會將SNAP文本置於androidBottom屬性的頂部。請協助

+0

可以顯示任何圖像,你想要什麼.. – Mohit

+0

已經添加了一個屏幕截圖。我試圖將SNAP文本放在按鈕圖像的頂部 – Blaze

+0

@JnG當您格式化xml代碼時,屬性將自動在xml文件中設置。你不能假設我想要第一個文本屬性。 –

回答

1

使用此代碼嘗試。

將此代碼替換爲您的xml文件。

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

    <Button 
     android:id="@+id/shutterButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:layout_weight="1" 
     android:background="#FFFFFF" 
     android:drawableBottom="@drawable/ic_question_answer_black_36dp" 
     android:text="SNAP" 
     android:textColor="#000000" 
     android:textSize="20sp"></Button> 
</RelativeLayout> 

這裏改變你的DrawableText Color和任何Background Color你所需要的。

此處的屏幕截圖。

enter image description here

它會給你Text上面繪製。

編輯1:

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:background="#338FD8D8" 
     android:orientation="horizontal" 
     android:paddingBottom="10dp" 
     android:paddingTop="10dp"> 

     <Button 
      android:id="@+id/shutterButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="#00FFFFFF" 
      android:drawableBottom="@drawable/ic_question_answer_black_36dp" 
      android:padding="5px" 
      android:text="SNAP" 
      android:textColor="#000000" /> 

     <Button 
      android:id="@+id/shutterButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="#00FFFFFF" 
      android:drawableBottom="@drawable/ic_question_answer_black_36dp" 
      android:padding="5px" 
      android:text="xxx" 
      android:textColor="#000000" /> 

     <Button 
      android:id="@+id/shutterButton2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="#00FFFFFF" 
      android:drawableBottom="@drawable/ic_question_answer_black_36dp" 
      android:padding="5px" 
      android:text="xxx" 
      android:textColor="#000000" /> 


    </LinearLayout> 
</RelativeLayout> 

對於羣鍵截屏在這裏。

enter image description here

+0

坦率地說,這不起作用,當放置在一個linearlayout按鈕羣 – Blaze

+0

@JNG我無法得到你在說什麼?現在你想要什麼樣的按鈕組。 –

+0

上面的代碼片段被放置在一個按鈕組中的線性佈局 – Blaze

0

是否必須在xml中使用layout_weight?如果沒有,我認爲只需從xml中的按鈕中刪除它。如果您有很多視圖添加到您的佈局中,它會使您的可繪製文本和文本在您的按鈕中變得混亂。

像這樣的: 如果我只是在我的佈局中添加3按鈕,一切都完美運行

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 


    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableBottom="@drawable/star_yellow" 
     android:layout_weight="1" 
     android:id="@+id/shutterButton" 
     android:padding="5px" 
     android:text="SNAP"></Button> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableBottom="@drawable/star_yellow" 
     android:layout_weight="1" 
     android:id="@+id/shutterButton1" 
     android:padding="5px" 
     android:text="SNAP"></Button> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableBottom="@drawable/star_yellow" 
     android:layout_weight="1" 
     android:id="@+id/shutterButton2" 
     android:padding="5px" 
     android:text="SNAP"></Button> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableBottom="@drawable/star_yellow" 
     android:layout_weight="1" 
     android:id="@+id/shutterButton4" 
     android:padding="5px" 
     android:text="SNAP"></Button> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/fragmentMain_RvTourList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     /> 
</LinearLayout> 

enter image description here

但是,如果我在我的佈局增添了不少按鈕和1 recyclerview,在所有的按鈕上的文本,並繪製會亂碼

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


     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton" 
      android:padding="5px" 
      android:text="SNAP"></Button> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton1" 
      android:padding="5px" 
      android:text="SNAP"></Button> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton2" 
      android:padding="5px" 
      android:text="SNAP"></Button> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton4" 
      android:padding="5px" 
      android:text="SNAP"></Button> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton5" 
      android:padding="5px" 
      android:text="SNAP"></Button> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton6" 
      android:padding="5px" 
      android:text="SNAP"></Button> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton7" 
      android:padding="5px" 
      android:text="SNAP"></Button> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton8" 
      android:padding="5px" 
      android:text="SNAP"></Button> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableBottom="@drawable/star_yellow" 
      android:layout_weight="1" 
      android:id="@+id/shutterButton9" 
      android:padding="5px" 
      android:text="SNAP"></Button> 
     <android.support.v7.widget.RecyclerView 
      android:id="@+id/fragmentMain_RvTourList" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      /> 
    </LinearLayout> 

enter image description here

如果我改變的方向是水平的,佈局是:

enter image description here

最後,改變你的文字顏色和背景顏色上的按鈕,避免兩者性質相同的顏色。

+0

不工作應該 – Blaze

+0

你可以請做到這一點wrap_content看看會發生什麼android:layout_width =「match_parent」 – Blaze

+0

我已經改變了它 – itsa04g9