2016-04-26 64 views
0

想要在ImageView上顯示TextView和Button我嘗試了但ImageView隱藏Button和TextView幫助我可以做什麼我在不同的佈局中嘗試它我更新了新代碼,面對在ImageView上顯示TextView和按鈕

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



<ImageView 
    android:id="@+id/imageview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="fitXY" > 
</ImageView> 
<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_below="@+id/imageview" 
    > 

</RelativeLayout> 

<Button 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Button" 
    android:id="@+id/btn_booking" 
    android:layout_gravity="right" 
    android:gravity="bottom" 
    android:layout_alignBottom="@+id/text_booking" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="Medium Text" 
    android:id="@+id/text_booking" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 
    </RelativeLayout> 
+0

張貼您的完整的xml代碼在這裏。有些部分仍然缺失。 –

+0

Sagar Nayak我現在編輯或更新代碼 – Ahmad

+0

想要在imageview上顯示按鈕和textview?你有任何形象的ImageView設置? –

回答

0

使用RelativeLayout作爲根佈局:

<?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"> 
    <ImageView 
     android:id="@+id/imageview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" > 
    </ImageView> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="Medium Text" 
     android:id="@+id/text_booking" 
     /> 
    <Button 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/btn_booking" 
     android:layout_gravity="right" 
     android:gravity="bottom" 
     android:layout_marginLeft="180dp"/> 
    </LinearLayout> 
</RelativeLayout> 
0

1)改變你的主要的LinearLayout(第一個)的RelativeLayout

2)在你的小組的LinearLayout(第二個)使用 -

android:layout_above="@+id/imageview" 
android:alignParentBottom="true" 

UPDATE

請檢查一下 -

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

<ImageView 
    android:id="@+id/imageview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@mipmap/ic_launcher"/> 

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_above="@+id/imageview" 
android:alignParentBottom="true" 
android:weightSum="2" 
android:orientation="horizontal"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:weight="1" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="Medium Text" 
    android:id="@+id/text_booking"/> 

<Button 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Button" 
    android:id="@+id/btn_booking" 
    android:weight="1"/> 

</RelativeLayout> 

希望這將有助於:)

+1

好的..適合那 –

+0

Onkar Nane我不明白請在代碼中解釋? – Ahmad

+1

檢查我更新的評論 –

0

外觀在我的代碼我最近使用它我使用父佈局(RelativeLayout)並設置爲父佈局的免費圖像也改變在java中的背景和內部父佈局添加圖像和文本你想要什麼.......!希望它能幫助你。

<RelativeLayout 
      android:id="@+id/frontLay" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/note0"> 

      <TextView 
       android:id="@+id/imageOne" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="50dp" 
       android:background="@drawable/onecircle" 
       android:tag="1" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textSize="25dp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/imageTwo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignEnd="@+id/imageOne" 
       android:layout_alignRight="@+id/imageOne" 
       android:layout_below="@+id/imageOne" 
       android:layout_marginEnd="17dp" 
       android:layout_marginRight="17dp" 
       android:layout_marginTop="15dp" 
       android:background="@drawable/twocircle" 
       android:tag="2" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textSize="25dp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/imageThree" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@+id/imageTwo" 
       android:layout_marginLeft="35dp" 
       android:layout_marginStart="35dp" 
       android:layout_toEndOf="@+id/imageSix" 
       android:layout_toRightOf="@+id/imageSix" 
       android:background="@drawable/threecircle" 
       android:tag="3" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textSize="25dp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/imageFour" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@+id/imageTwo" 
       android:layout_alignParentTop="true" 
       android:layout_alignStart="@+id/imageTwo" 
       android:layout_marginTop="29dp" 
       android:background="@drawable/fourcircle" 
       android:tag="4" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textSize="25dp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/imageFive" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/imageTwo" 
       android:layout_toLeftOf="@+id/imageEight" 
       android:layout_toStartOf="@+id/imageEight" 
       android:background="@drawable/fivecircle" 
       android:tag="5" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textSize="25dp" 
       android:textStyle="bold" 
       android:visibility="invisible" /> 

     </RelativeLayout> 
0

只需添加這兩行,我的問題就解決了。

android:layout_toLeftOf="@+id/btn_booking" 
android:layout_toStartOf="@+id/btn_booking" 
0

奇怪大家都建議你使用RelativeLayout,而你應該使用FrameLayout用於這種東西。使用FrameLayout可以非常容易地實現這一點,而不是RelativeLayout,因爲RelativeLayout在繪圖時非常昂貴。要達到你要求的你應該使用這個簡單的組合:

FrameLayout>ImageView>LinearLayout(with layout_gravity){Button,TextView}/>