2017-02-08 64 views
0

我試圖讓我看起來在我的圖像上繪製,但ImageView隱藏在按鈕後面,因此它不可見。我已經嘗試了所有我知道的Android命令,但似乎沒有任何工作。使圖像重疊另一

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    > 


    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:src="@drawable/football" 
      android:id="@+id/imageView" 
      android:layout_centerVertical="true" 
      /> 

     <Button 
      android:id="@+id/football_button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/football" 
      android:textAlignment="center" 
      android:textAllCaps="true" 
      /> 


    </RelativeLayout> 

所需的外觀: enter image description here

回答

0

如果你想在ImageView的是旁邊的按鈕,你可以添加toRightOf到按鈕。

如果您希望ImageView位於按鈕的頂部,請在ImageView之前放置Button並將android:elevation="2dp"添加到ImageView。

0

你應該在你的按鈕使用drawableLeft所以你的XML會是這樣的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin"> 

<Button 
    android:id="@+id/football_button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/football" 
    android:text="@string/football" 
    android:textAlignment="center" 
    android:textAllCaps="true" /> 

+0

雖然這是完全真實的,但應該指出的是,雖然這是最簡單的方式這樣做,你在使用時會失去一些定位控制。即我沒有在我的項目中使用它,因爲我無法完全控制drawable的位置。如果OP需要他的物品的高級定位,他可能會更好,只是使用不同的佈局。 –