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>
आपके इनपुट के लिए धन्यवाद का उपयोग करता है।
हाय करने से रोकता है, यह काम करता है, हालांकि के रूप में मैं गुमराह आप ImageButton में अपनी beacause एक काफी बड़ी छवि हो सकता है, है, इसलिए यदि मैं चाहता हूँ स्क्रीन की ऊंचाई के 2/5 एस में शुरू करने के लिए, इसलिए यह स्क्रीन के केंद्र बिंदु को कवर करता है। अगर मैं आपके सुझाए गए उत्तर का उपयोग करता हूं तो यह बटन को केंद्र से दूर धक्का देता है और इसे कवर करने की अनुमति नहीं देता है। – urSus
हम्म, शायद पैडिंग को बदलने की कोशिश करें पैडिंग के साथ टॉप? –
ओह, मैं वास्तव में इसे गलत पढ़ता हूं, केंद्रित नकली दृश्य पर पैडिंग सेट बिल्कुल काम नहीं करता है। ऊपर दिए गए बटन पर पैडिंग सेट करना बस ऊपर की ओर बटन दबाता है जो मेरे लिए समाधान नहीं है क्योंकि मैं इसे मध्य बिंदु – urSus