2012-07-27 10 views
22

im केंद्र में नहीं वास्तव में मेरी बटन स्थिति है, लेकिन स्क्रीन ऊंचाई के 2/5s में कहते हैं की सुविधा देता है की कोशिश कर रहा, मैं असफल विशेषता के लिए देख रहा था, तो मैं इस दृष्टिकोण की कोशिश कीएंड्रॉइड में केंद्र से देखने को ऑफ़सेट करने का कोई तरीका है?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
android:padding="20dp" > 

<ImageButton 
    android:id="@+id/flashlight_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_above="@+id/fakeView" 
    android:background="@null" 
    android:contentDescription="@string/flashlight_button_description" 
    android:src="@drawable/freeml_bright" /> 

    <View 
    android:id="@+id/fakeView" 
    android:layout_width="10dp" 
    android:layout_height="10dp" 
    android:layout_centerInParent="true" 
    android:background="#FFAABB" /> 

</RelativeLayout> 

लेकिन यह काम नहीं करता है , भले ही मैं नकली दृश्य पर मार्जिन सेट करता हूं।

कोई विचार?

// संपादित //

धन्यवाद तुम लोगों के जवाब, गद्दी विशेषता काम करता है, लेकिन के रूप में यह एक बड़ा छवि है और अगर मैं इसे स्क्रीन ऊंचाई के 2/5ths पर शुरू करना चाहते हैं के लिए, यह केंद्र बिंदु को शामिल किया गया स्क्रीन का, इसलिए यदि मैं पैडिंग विशेषता का उपयोग करता हूं तो यह काम करता है लेकिन यह इसे केंद्र से दूर चलाता है और इसे कवर करने की अनुमति नहीं देता है। क्षमा करें मेरे खराब

हालांकि, मैंने इसे रैखिक लेआउट का उपयोग करके काम किया है, जिसे मैं टालना चाहता था क्योंकि एक दूसरे के बगल में ऊपर और नीचे पर अधिक दृश्य हैं, इसलिए यह रैखिक लेआउट का उपयोग करके घोंसला वाले दृश्यों का कारण बन जाएगा। दुर्भाग्य से मुझे लगता है कि यह एकमात्र विकल्प है।

यह मूल रूप से यह एक और रेखीय लेआउट कि ऊंचाई = 0dp और वजन = 1 के साथ ऊपर और नीचे देखा गया अप्रयुक्त छोड़ शेष स्थान को भरता है और इसकी गुरुत्वाकर्षण सेट केंद्र के लिए

<?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:orientation="vertical" 
android:padding="20dp"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:gravity="center" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/application_logo_description" 
     android:src="@drawable/mylight" /> 

    <ImageButton 
     android:id="@+id/settings_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:background="@null" 
     android:contentDescription="@string/settings_button_description" 
     android:src="@drawable/settings_button" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <ImageButton 
     android:id="@+id/flashlight_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:contentDescription="@string/flashlight_button_description" 
     android:src="@drawable/flashlight_button_selector" /> 

    <View 
     android:id="@+id/fakeView" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginTop="60dp" 
     android:background="#FFAABB" /> 
</LinearLayout> 

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|center_horizontal" 
    android:contentDescription="@string/powered_by_description" 
    android:src="@drawable/powered_by" /> 

<ImageButton 
    android:id="@+id/ad_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|center_horizontal" 
    android:background="@null" 
    android:contentDescription="@string/ad_button_description" 
    android:src="@drawable/freeml" /> 

</LinearLayout> 

आपके इनपुट के लिए धन्यवाद का उपयोग करता है।

उत्तर

3

तो जैसे मार्जिन, उपयोग गद्दी (ऊपर) का उपयोग न करें,:

<View 
android:id="@+id/fakeView" 
android:layout_width="10dp" 
android:layout_height="10dp" 
android:layout_centerInParent="true" 
android:paddingTop="80dp" 
android:background="#FFAABB" /> 

, काम करना चाहिए यही कारण है कि हालांकि मैं यह परीक्षण नहीं किया गया है!

+0

हाय करने से रोकता है, यह काम करता है, हालांकि के रूप में मैं गुमराह आप ImageButton में अपनी beacause एक काफी बड़ी छवि हो सकता है, है, इसलिए यदि मैं चाहता हूँ स्क्रीन की ऊंचाई के 2/5 एस में शुरू करने के लिए, इसलिए यह स्क्रीन के केंद्र बिंदु को कवर करता है। अगर मैं आपके सुझाए गए उत्तर का उपयोग करता हूं तो यह बटन को केंद्र से दूर धक्का देता है और इसे कवर करने की अनुमति नहीं देता है। – urSus

+0

हम्म, शायद पैडिंग को बदलने की कोशिश करें पैडिंग के साथ टॉप? –

+0

ओह, मैं वास्तव में इसे गलत पढ़ता हूं, केंद्रित नकली दृश्य पर पैडिंग सेट बिल्कुल काम नहीं करता है। ऊपर दिए गए बटन पर पैडिंग सेट करना बस ऊपर की ओर बटन दबाता है जो मेरे लिए समाधान नहीं है क्योंकि मैं इसे मध्य बिंदु – urSus

3

विशेषता एंड्रॉयड प्रयोग करके देखें: लक्ष्य डिवाइस के स्क्रीन आकार के आधार पर "@ + id/fakeView"

+0

+1 को कवर करना चाहता हूं यह शानदार है! –

32

layout_toLeftOf =, एक्स डी पी द्वारा गद्दी यह ऊंचाई की बस एक पांचवें हिस्से से अधिक के लिए कदम हो सकता है।

आपको इस आंदोलन को स्वयं कोड करना पड़ सकता है।

लेकिन फिर, कुछ भी नहीं तुम क्या कर

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
android:padding="20dp" > 

<View 
android:id="@+id/fakeView" 
android:layout_width="10dp" 
android:layout_height="10dp" 
android:layout_centerInParent="true" 
android:background="#FFAABB" /> 

<ImageButton 
android:id="@+id/flashlight_button" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_centerHorizontal="true" 
android:layout_above="@+id/fakeView" 
android:marginBottom="50dp" 
android:background="@null" 
android:contentDescription="@string/flashlight_button_description" 
android:src="@drawable/freeml_bright" /> 

+0

+1 अच्छा काम करता है। –

+0

धन्यवाद श्रीमान :) – Shark

+5

बीच में एक नकली दृश्य! यह बॉक्स के बाहर सोच रहा है, बस मुझे क्या चाहिए! :) –

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

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