2012-09-13 20 views
6

साथ बटन मैं निम्नलिखित लेआउटएंड्रॉयड बाएं और दाएं मार्जिन

<?xml version="1.0" encoding="utf-8"?> 

<Button 
    android:id="@+id/sign_in" 
    style="@style/ButtonText" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/custom_button_green" 
    android:text="@string/signin_via_email" 
    android:textSize="15sp" 
    android:typeface="sans" /> 

अब बटन मुझे नहीं वास्तव में पूरी चौड़ाई फिट करने के लिए चाहते हैं न कि मैं एक मार्जिन चाहते हैं बाईं ओर से 10 डीपी और दाईं ओर से 10 डीपी। मैंने पैडिंग और लेआउट_मार्गिन लिफ्ट और सही विशेषताओं को सेट किया है लेकिन वे काम नहीं करते हैं। कोई मदद ?

सधन्यवाद

+1

आप अपने ButtonText शैली कोड पोस्ट कर सकते हैं? –

+0

'एंड्रॉइड: layout_width =" wrap_content "' और इसके अनुसार मार्जिन निर्दिष्ट करें। – neevek

उत्तर

0

हैलो उपयोगकर्ता,

कृपया कभी ऊंचाई पर "fill_parent" का उपयोग नहीं करते। कृपया वास्तविक छवि ऊंचाई और वजन दें और फिर मार्जिन लेफ्ट और दाएं रखें। यह निश्चित रूप से काम करेगा।

+0

लेकिन क्या मैं स्क्रीन की चौड़ाई की गणना कर सकता हूं। मैं बस बाईं ओर और स्क्रीन के दाईं ओर 10 डीपी का मार्जिन चाहता हूं। यह काम करना चाहिए? – AndroidDev

14
<Button 
style="@style/ButtonText" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
android:id="@+id/btnOk" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="OK" /> 
+7

@ user365019: ओकी तो आप जवाब भी स्वीकार कर सकते हैं – MAC

+0

यदि आप "android: layout_marginHorizontal =" 10dp "का उपयोग करते हैं तो यह भी काम करता है। ध्यान दें कि layout_marginHorizontal केवल API 26 या उच्चतर के लिए काम करता है! – Lotan

0

इस लेआउट यह अपने बटन के लिए मार्जिन जोड़ देगा, अगर बटन अपने मूल तत्व है उपयोग तो कोई रास्ता है कि लेआउट से मार्जिन जोड़ने के लिए कुछ अन्य लेआउट के लिए बटन जोड़ने आप मार्जिन/padding

निर्दिष्ट कर सकते हैं, जबकि है
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="10dip" 
android:paddingRight="10dip" > 
<Button 
    android:id="@+id/sign_in" 
    style="@style/ButtonText" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/custom_button_green" 
    android:text="@string/signin_via_email" 
    android:textSize="15sp" 
    android:typeface="sans" /> 
</LinearLayout> 
2

मैं

input.xml 
को

android:padding="10dp" 

जोड़ा

.. और यह काम किया!

(मैं SoftKeyboard स्रोत कोड का उपयोग कर और भी एक ही समस्या है)

संबंधित मुद्दे