2012-08-14 13 views
14

में एक और imageView के शीर्ष पर एक imageView जगह यह मेरा लेआउट जो मैं किसी भी सफलताकैसे एंड्रॉयड

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/white"> 

<LinearLayout 
    android:id="@+id/lltest" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_centerHorizontal="true"> 

     <ImageView 
     android:id="@+id/inside_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dip" 
     android:layout_marginBottom="5dip" 
     android:src="@drawable/frame"/> 

</LinearLayout> 

<ImageView 
     android:id="@+id/outside_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/inside_imageview" 
     android:scaleType="fitXY"/> 
</RelativeLayout> 

क्या मैं वास्तव में चाहते हैं सटीक साथ inside_imageview की चोटी पर मेरी outside_imageview है बिना अब तक की कोशिश की है ऊंचाई और चौड़ाई ... लेआउट के माध्यम से इसे कैसे करें?

+0

आप layout_alignLeft जोड़ने की कोशिश की = "है @ id/inside_imageview "alignTop के अलावा? – CSmith

+0

@CSmith हाँ मैंने कोशिश की। –

+0

समस्या यह थी कि उसके अंदर एक_रिएज व्यूइंग है जिसमें एक LinearLayout के अंदर दृश्य है 'layout_alignTop' संदर्भ आईडी को 'inside_imageView' में नहीं देख सकता है। 'बाहरी_imageview' लाइनरलाइट पर संरेखित होगा यदि आईडी संदर्भ इसके बजाय 'lltest' था। – DeeV

उत्तर

34
<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/white" > 

    <ImageView 
     android:id="@+id/inside_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dip" 
     android:layout_marginTop="5dip" 
     android:src="@drawable/frame" /> 

     <ImageView 
     android:id="@+id/outside_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/inside_imageview" 
     android:layout_alignBottom="@id/inside_imageview" 
     android:layout_alignLeft="@id/inside_imageview" 
     android:layout_alignRight="@id/inside_imageview"    
     android:scaleType="fitXY" /> 
    </RelativeLayout> 

RelativeLayout में layout_align[Top|Bottom|Left|Right] विशेषता मार्जिन के भीतर उनके संबंधित x और y मूल्यों पर आधारित विचारों संरेखित करने के लिए प्रयोग किया जाता है। दूसरा ImageView अब मार्जिन के आधार पर पहले ImageView के शीर्ष, नीचे, बाएं और दाएं से गठबंधन किया जाएगा। संरेखण में पैडिंग को नजरअंदाज कर दिया जाता है।

+0

हम्म के डिजाइन दृश्य में सही ढंग से दिखाया जा रहा है ... असल में मेरे पास inner_imageview के साथ दो और छविदृश्य हैं ... इसलिए मैं उन्हें एक अलग लाइनरलेआउट में डालने का विचार ... आंतरिक मुझे एक क्षैतिज अभिविन्यास करने की आवश्यकता है और बाहरी एक मैं एक लंबवत चाहता हूं ... तो कृपया मुझे इस –

+0

में सुझाव दें जो चीजों को थोड़ा और जटिल बनाता है। आप उन विचारों का संदर्भ नहीं दे सकते जो कि अन्य विचारों में बच्चे हैं। वे केवल उसी स्तर पर बच्चों के संदर्भ स्वीकार करते हैं। यदि 'अंदर_imageview' और' outside_imageview' समान चौड़ाई और ऊंचाई हैं, तो आपको केवल उन्हें दो अलग-अलग 'लाइनरलेआउट्स' में रखना होगा और ऊपर और बाईं ओर दो 'लीनियर लेआउट्स' को संरेखित करना होगा। यदि आयाम व्यापक रूप से भिन्न हैं, तो आपको दूसरे के लिए 'layout_below' और' layout_toRightOf' का उपयोग करना पड़ सकता है। – DeeV

+0

महान जवाब! इसे प्यार करना ! – uLYsseus

6

आपको FrameLayout आज़माएं। एक फ्रेम के अंदर प्रत्येक बच्चा एक दूसरे के शीर्ष पर है।

+0

डिवाइस और 2 छवियों पर केवल 1 छवि दिखायी जा रही है, दूसरे के शीर्ष पर एक लेआउट – iOSAndroidWindowsMobileAppsDev

4

आपको एक फ्रेम लेआउट की आवश्यकता है। AndroidFrameLayout जांचने का प्रयास करें।

+0

डिवाइस और 2 छवियों पर केवल 1 छवि दिखायी जा रही है, दूसरे के शीर्ष पर एक लेआउट – iOSAndroidWindowsMobileAppsDev

19

FrameLayout आपको जो चाहिए वह है। आप बस पेरेंट लेआउट को मर्ज कर सकते हैं जो FrameLayout भी है। Android डेवलपर ब्लॉग पर एक नज़र डालें: http://android-developers.blogspot.it/2009/03/android-layout-tricks-3-optimize-by.html

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center"> 

    <ImageView 
     android:id="@+id/outside_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY"/> 

    <ImageView 
     android:id="@+id/inside_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dip" 
     android:layout_marginBottom="5dip" 
     android:src="@drawable/frame" /> 
</merge> 
+2

के डिजाइन दृश्य में सही ढंग से दिखाया जा रहा है, दुख की बात है कि जिस व्यक्ति ने सवाल पूछा है, वह समझ में नहीं आता है और यह भी नहीं चाहता समझने के लिए कि फ्रेम लेआउट क्या कर सकता है और हम सभी को कम कर दिया। आप दो लोगों को उखाड़ फेंक दिया :) –

+0

यह एक स्तर से दृश्य पदानुक्रम को भी कम करता है: woot: –

+0

अच्छा समाधान। फ़्रेमलाउट निश्चित रूप से जाने का तरीका है। – nurxyz

0

मैं इस तरह से करने की कोशिश की और यह मेरे लिए काम किया, आशा है कि यह मदद करता है

<FrameLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="5dip"> 
<ImageView 
    android:id="@+id/image_first" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/imga"/> 
<ImageView 
    android:id="@+id/imageview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/image"/> 
</FrameLayout> 
+0

का उपयोग करने की आवश्यकता नहीं है डिवाइस पर केवल 1 छवि दिखायी जा रही है और 2 छवियां हैं, एक दूसरे के शीर्ष पर एक है – iOSAndroidWindowsMobileAppsDev

+0

लेआउट के डिज़ाइन व्यू में सही ढंग से दिखाया जा रहा है, तो समस्या –

1
   <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:padding="@dimen/_15dp"> 
       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:padding="@dimen/_10dp" 
        android:layout_marginTop="@dimen/_50dp" 
        android:background="@drawable/white_background" 
        /> 
       <ImageView 
        android:layout_width="@dimen/_100dp" 
        android:layout_height="@dimen/_100dp" 
        android:background="@drawable/my_credit" 
        android:layout_marginTop="@dimen/_5dp" 
        android:layout_centerHorizontal="true" 
        /> 
      </RelativeLayout> 
+0

क्या हो सकती है क्या आप समझा सकते हैं कि आपका कोड वास्तव में क्या करता है? – Alex

+0

यह एक अन्य कल्पना के ऊपर एक छविदृश्य रखता है ... किसी भी फ्रेम लेआउट का उपयोग करने की कोई आवश्यकता नहीं है – Sunil