2010-01-21 17 views
9

में छवि लंबवत केंद्र को कैसे संरेखित कर सकता हूं मेरे पास निम्न लेआउट है, जो बाईं ओर 1 आइकन है और दाईं ओर 2 टेक्स्ट दृश्य (एक दूसरे के शीर्ष पर ढेर) है। मैं पैनल में टेक्स्ट 1 लंबवत केंद्र रखना चाहता हूं और जब मैं टेक्स्ट 2 Visible.GONE बना देता हूं। क्या आप कृपया मुझे बता सकते हैं कि मैं यह कैसे कर सकता हूं?मैं रैखिक लेआउट

<RelativeLayout android:id="@+id/panel" 
     android:layout_width="fill_parent" 
     android:layout_height="?android:attr/listPreferredItemHeight"> 
    <ImageView 
     android:id="@+id/icon1" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center_vertical"/> 
    <TextView android:id="@+id/text1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/icon1" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:layout_gravity="center_vertical"/> 
    <TextView android:id="@+id/text2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/icon1" 
     android:layout_below="@id/text1" 
     android:textAppearance="?android:attr/textAppearanceSmall"/> 
    </RelativeLayout> 
+0

एंड्रॉइड: layout_alignParentTop = "true" - यही कारण है कि –

उत्तर

9

मैं इसे केवल तीन विचारों के साथ एक सापेक्ष लेआउट में बदल दूंगा। और आप सामग्री को संरेखित करने के लिए android:layout_centerHorizontal, android:layout_centerVertical का भी उपयोग कर सकते हैं।

+0

धन्यवाद। वर्तमान LinearLayout का उपयोग कर संरेखण को ठीक करने का कोई तरीका है? – hap497

15

आपको अपने पहले उदाहरण में android:gravity को 0Vपर ImageView पर प्रतिस्थापित करने के लिए करना है। यह सब है :)

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