我想在Android Activity
中發出通知Button
,與Facebook中的通知按鈕相同。我試過ImageButton
和Button
這樣做,但我無法在同一圖層上顯示在圖像上繪製的文本。爲什麼?Facebook上的Android佈局中的文本像消息按鈕中的圖像
回答
如果我得到你的問題的權利,你需要一個包含通知的計數的紅色圓圈,您創建一個可繪製,並用它作爲你的TextView
這裏背景是一個樣本圓角邊緣的矩形形狀
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<solid android:color="#FFFFFF"/>
<corners android:radius="3dp"/>
</shape>
</item>
<item>
<shape>
<corners android:radius="3dp"/>
<solid android:color="#F00"/>
</shape>
</item>
</layer-list>
然後,所有你需要的是使用它作爲您的TextView
編輯背景:使用的FrameLayout使通知出現在ImageView的
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image" />
<TextView
android:id="@+id/notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:background="@drawable/red_notification_frame"
android:gravity="center"
android:minWidth="15dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:textColor="#fff"
android:textStyle="bold" />
</FrameLayout>
並更改TextView的layout_gravity以控制其在圖像上的位置。
不,你沒有得到是我想讓這個屏幕在這個鏈接https://encrypted-tbn1.gstatic.com/圖像q = TBN:ANd9GcQ4MdSPm7hFQlijZKKnStYuyLy2m4u94pPFKdX2ktMt58Bi5fq2 – 2013-03-15 15:55:48
@SaidGamal使用的FrameLayout做出的TextView與你的ImageView頂部的紅色背景 – 2013-03-15 16:01:21
是的,我已經做到了,但如何使在圖像上沒有它上面的文本視圖,這是我的問題非常感謝爲你的幫助 – 2013-03-15 16:08:57
如果您想要在圖像上顯示永久文本,則快捷方式選項是使用圖像編輯軟件並將文本寫入圖像。 然後使用ImageButton並放置圖像。
我修改的答案,一個解決方案
<RelativeLayout
android:layout_height="102dp"
android:layout_width="102dp"
android:padding="15dp">
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/envelope" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="1dp"
android:layout_height="12dp"
android:layout_alignLeft="@+id/myImageView"
android:layout_alignTop="@+id/myImageView"
android:layout_alignRight="@+id/myImageView"
android:layout_alignBottom="@+id/myImageView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="43dp"
android:layout_marginLeft="43dp"
android:gravity="center"
android:text="0"
android:background="@drawable/rounded_corners"
android:textColor="@android:color/white" />
</RelativeLayout>
XML風格上來,把它放在繪製
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="@android:color/holo_red_dark" />
<solid android:color="@android:color/holo_red_light" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="20dp" />
</shape>
在我的情況下,當文本beyong 3個字符,我說9+
- 1. Android圖像按鈕佈局
- 2. 帶有圖像按鈕的Android佈局
- 3. 設計佈局像下面的圖像按鈕圖像中的Android
- 4. Android:如何佈局按鈕,使文本看起來像截圖中的一個?
- 5. 相對佈局中的圖像按鈕android not shown the image
- 6. Android - 如何佈局圖像中的按鈕?
- 7. ANdroid:動態添加圖像按鈕到表佈局中的行
- 8. JSF中的文本和圖像佈局
- 9. Tkinter:在網格佈局中的按鈕上方獲取圖像
- 10. Xamarin跨平臺窗體的圖像和文本佈局按鈕
- 11. 發佈圖像與來自android的facebook上的文本
- 12. SWT按鈕上的文本和圖像
- 13. Android佈局繞過圖像文本
- 14. 在Android中的圖像按鈕上設置前景圖像
- 15. 在圖像上方的Android佈局
- 16. Facebook像不同圖像的按鈕
- 17. 如何在按鈕中設置文本中的圖像 - android?
- 18. Android佈局 - 設置圖像按鈕之間的間距
- 19. 圖像上的佈局
- 20. 圖像佈局android
- 21. 如何將網格佈局中的圖像按鈕居中 - Android Studio
- 22. c中的圖像按鈕上的文本#
- 23. 如何在Android中的圖像按鈕下添加文本?
- 24. 消息像Windows Phone中的文本框
- 25. 包含的佈局中的圖像按鈕不會觸發onclicklistener上ActionDown
- 26. 在Android的按鈕上設置圖像?
- 27. 在android中的按鈕圖像大小
- 28. 更改android中的按鈕圖像
- 29. 在android中變化的圖像按鈕
- 30. Facebook中的每個圖像的Facebook Share按鈕
您的意思是包含計數或包含整個通知文本的氣泡的小紅圈?你在這裏很曖昧 – 2013-03-15 15:32:54
這是你的代碼 – stinepike 2013-03-15 15:33:55
是的,你是對的,你得到了我所需要的 – 2013-03-15 15:37:00