के बाईं ऊपरी हिस्से पर बैज बबल को पोजिशन करना मैं अपने गतिविधि के बटन में से किसी एक को बैज जोड़ने की कोशिश कर रहा हूं। अभी मैं एक्सएमएल करने की कोशिश कर रहा हूं। बैज के साथ बटन, इस तरह दिखना चाहिए:बटन
मैं पहले से ही बुलबुला और एक RelativeLayout
का उपयोग कर के अंदर का पाठ किया है:
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/badge"
android:layout_centerInParent="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="2"
android:layout_centerInParent="true" />
</RelativeLayout>
लेकिन मैं एक तरह से नहीं मिल सकता है इसे वहां रखने और इसे एक ही एक्सएमएल के साथ चित्र और परिदृश्य पर काम करने के लिए। दो संसाधनों
<Button android:id="@+id/new_releases_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/new_releases_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:layout_marginTop="15dp"
android:layout_below="@id/coming_soon_button"
android:onClick="newReleaseClick"
android:layout_centerHorizontal="true" />
<Button android:id="@+id/top_sellers_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/top_sellers_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:layout_marginTop="15dp"
android:layout_below="@id/new_releases_button"
android:onClick="topSellersClick"
android:layout_centerHorizontal="true" />
और यहाँ कर रहे हैं:
मैं एक्सएमएल कैसे करना चाहिए
buttoms Activity
में इस तरह कर रहे हैं?
संपादित करें: बेस्ट दृष्टिकोण अब तक, लेकिन यह अभी भी काम नहीं करता:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/discounts_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/discounts_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:onClick="discountsClick"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"/>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/badge"
android:layout_centerInParent="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="20"
android:layout_centerInParent="true" />
</RelativeLayout>
</FrameLayout>
यह सही तरीका की तरह लग रहा है, लेकिन मैं अभी भी यह काम नहीं कर सकता। बैज में 'मार्जिनटॉप' और 'मार्जिन लिफ्ट' जोड़ने का अर्थ है, लेकिन वे नकारात्मक होना चाहिए। यह दृश्य के बाहर यह स्थिति है। तो इसके बजाय, मैंने बटन पर सकारात्मक 'मार्जिनटॉप' और 'मार्जिन लिफ्ट' जोड़ा, लेकिन उन मानों को अनदेखा कर दिया गया है। मैं अभी तक समझ में नहीं आया क्यों। मैं अभी तक सबसे अच्छे दृष्टिकोण के साथ प्रश्न संपादित कर दूंगा। – Macarse
हाँ, सही। छवि के लिए कोई नकारात्मक मार्जिन नहीं है (हालांकि मैंने कोशिश नहीं की है कि यह भी काम करेगा), आप अपनी पसंद के अनुसार छवि और बटन दोनों के लिए शीर्ष/बाएं मार्जिन के साथ काम कर सकते हैं। लेकिन यह इस तरह से समझ में आता है: फ्रेमलेआउट की ऊपरी बाएं हाथ की स्थिति छवि के ऊपरी बाएं कोने है, इसलिए आपको बटन को थोड़ा और नीचे ले जाने की आवश्यकता है। –
कूल, 'एंड्रॉइड जोड़ना: layout_gravity = "शीर्ष | बाएं" बटन ने इसे काम किया है, लेकिन यह बटन को काटता है क्योंकि मेरे माता-पिता से मेरी चौड़ाई और ऊंचाई "wrap_content" है। मैं 'एंड्रॉइड: लेआउट_हेइट =" 60 डीपी "जैसे कुछ को मजबूर नहीं करना चाहता हूं जो अच्छा दिखता है। इसे हल करने के बेहतर तरीके का कोई विचार? – Macarse