मेरे पास ImageView
और TextView
है। मैं छवि दृश्य के नीचे TextView
रखना चाहता हूं लेकिन TextView
के बीच ImageView
(क्षैतिज धुरी के साथ) के बीच गठबंधन किया गया है। यदि TextView
में टेक्स्ट कुछ बड़े या छोटे में बदल जाता है, तो पाठ के बीच को हमेशा ImageView
के बीच में गठबंधन करने की आवश्यकता होती है। क्या यह xml
में संभव है?एंड्रॉइड: नीचे एक तत्व को संरेखित करें और दूसरे के बीच में
उत्तर
हाँ, आप बस एक ऊर्ध्वाधर LinearLayout
जो center_horizontal
को android:gravity
सेट है में दोनों तत्वों को रोकने के लिए देख रहे हैं।
कुछ इस तरह:
<?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:gravity="center_horizontal"
android:orientation="vertical"
... >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
... />
</LinearLayout>
क्योंकि TextView
की चौड़ाई wrap_content
है, इसकी गुरुत्वाकर्षण की स्थापना आवश्यक नहीं होना चाहिए। मैं सिर्फ सुरक्षा के लिए ऐसा करूंगा (और इसके अतिरिक्त, मैं चौड़ाई को match_parent
पर भी सेट कर सकता हूं)। ellipsezed = "अंत" :
यह शर्मनाक है क्योंकि मैं कोड में किसी अन्य स्थान पर पहले से ही ऐसा करता हूं। फिर भी धन्यवाद। – AndroidDev
तो, यह आपके उद्देश्य के लिए काम करता है? यदि यह समाधान है, तो इसे सही के रूप में चिह्नित करने पर विचार करें ताकि अन्य इसे भी ढूंढ सकें। – Eric
आप इसे तुरंत चिह्नित नहीं कर सकते हैं। आपको कई मिनट इंतजार करना है। मरीजों को। मैं लगभग हमेशा उन्हें चिह्नित करता हूं। – AndroidDev
TextView
android:layout_width="fill_parent"
सेट और TextView
में android:gravity="center"
निर्धारित किया है।
मुझे लगता है कि यह आपकी मदद करता है।
धन्यवाद
.. इस प्रकार आप RealtiveLayout का उपयोग कर सकते
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
... >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<TextView
android:layout_below="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
आप अपने TextView एक लाइन की उसके बाद ही हो निम्नलिखित गुण TextView को
एंड्रॉयड जोड़ना चाहते हैं एंड्रॉयड: singleLine = "true"
एक दिया लेआउट का उपयोग करें और अपने मौजूदा लेआउट के किसी भी आप प्राप्त करने के लिए इसे जोड़ने के परिणाम आपके लिए क्या देख ..
आशा है कि यह स्पष्टीकरण आपके लिए काम करता है ..
मध्य मध्य मध्य। –
मुझे लगता है कि इसे मध्यम पहेली कहा जाता है! –