2013-09-07 15 views
24

में सापेक्ष लेआउट मेरे पास एकाधिक "छविदृश्य" के साथ एक सापेक्ष लेआउट है और जब मैं स्क्रीन के चारों ओर घूमता हूं, तो छविदृश्य विकृत हो जाते हैं ... इसलिए मैंने इसे स्क्रॉल व्यू में लपेटने का निर्णय लिया ... लेकिन स्क्रॉल दृश्य नहीं है ' टी काम !!! क्या कोई मेरी मदद कर सकता है? मुझे पता है कि ग्रिडव्यू या लिस्टव्यू डिज़ाइन करने का सही तरीका है ... लेकिन चूंकि मेरे पास कुछ प्रश्न थे और किसी ने मुझे स्टैक ओवरफ्लो में जवाब नहीं दिया, मैंने इस तरह से जाने का फैसला किया।स्क्रॉलव्यू

<?xml version="1.0" encoding="utf-8"?> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ScrollView01" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:scrollbars="none" > 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 


    <Button 
     android:id="@+id/continuePizza" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="continue" /> 

    <Button 
     android:id="@+id/finishP" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/continuePizza" 
     android:layout_alignParentLeft="true" 
     android:text="finish" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="16dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView1" 
     android:layout_marginLeft="18dp" 
     android:layout_toRightOf="@+id/imageView1" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView1" 
     android:layout_marginTop="18dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView3" 
     android:layout_centerVertical="true" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView3" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView5" 
     android:layout_marginTop="17dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView2" 
     android:layout_alignTop="@+id/imageView5" 
     android:layout_marginLeft="10dp" 
     android:src="@drawable/download" /> 
    <ImageView 
     android:id="@+id/imageView8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView7" 
     android:layout_alignTop="@+id/imageView3" 
     android:src="@drawable/download" /> 

</RelativeLayout> 

</ScrollView> 

उत्तर

19

मैं स्क्रॉल दृश्य के भीतर सापेक्ष लेआउट इस मैं एक रेखीय लेआउट के साथ मेरी रिश्तेदार लेआउट के चारों ओर लिपटा काबू पाने के लिए के साथ एक ही समस्या का सामना करना है, इस तरह की कोशिश है और यह भी रिश्तेदार लेआउट

से उन्मुखीकरण निकालें: यहाँ मेरी एक्सएमएल कोड है
<?xml version="1.0" encoding="utf-8"?> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView01" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" 
android:scrollbars="none" > 

<LinearLayout android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 


<Button 
    android:id="@+id/continuePizza" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="continue" /> 

<Button 
    android:id="@+id/finishP" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/continuePizza" 
    android:layout_alignParentLeft="true" 
    android:text="finish" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="16dp" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView1" 
    android:layout_marginLeft="18dp" 
    android:layout_toRightOf="@+id/imageView1" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView1" 
    android:layout_marginTop="18dp" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView3" 
    android:layout_centerVertical="true" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView3" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView5" 
    android:layout_marginTop="17dp" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView7" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView2" 
    android:layout_alignTop="@+id/imageView5" 
    android:layout_marginLeft="10dp" 
    android:src="@drawable/download" /> 
<ImageView 
    android:id="@+id/imageView8" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView7" 
    android:layout_alignTop="@+id/imageView3" 
    android:src="@drawable/download" /> 

</RelativeLayout> 
</LinearLayout> 
</ScrollView> 
+0

मैं अपने समाधान किया है और इतने सारे त्रुटियों का सामना करना पड़ा! यहां तक ​​कि गतिविधि इस तरह से दिखाई नहीं देती है! :( –

+0

त्रुटि क्या है – Ravi

+0

मैं त्रुटियों की प्रतिलिपि बनाना चाहता था और इसलिए एप्लिकेशन को फिर से चलाने के लिए ... यह मजाकिया है कि अब कोई त्रुटि नहीं है लेकिन समस्या के लिए कोई फर्क नहीं पड़ता! मुझे अभी भी समस्या है ... –

-4

मैं और एक छोटा सा परिवर्तन प्रिय रवि की मदद से मेरे सवाल का समाधान कर सकता:

<?xml version="1.0" encoding="utf-8"?> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ScrollView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scrollbars="none" > 



     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="427dp" > 



<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="548dp" > 




    <Button 
     android:id="@+id/continuePizza" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="continue" /> 

    <Button 
     android:id="@+id/finishP" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/continuePizza" 
     android:layout_alignParentLeft="true" 
     android:text="finish" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="16dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView1" 
     android:layout_marginLeft="18dp" 
     android:layout_toRightOf="@+id/imageView1" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView1" 
     android:layout_marginTop="18dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView3" 
     android:layout_centerVertical="true" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView3" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView5" 
     android:layout_marginTop="17dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView2" 
     android:layout_alignTop="@+id/imageView5" 
     android:layout_marginLeft="10dp" 
     android:src="@drawable/download" /> 
    <ImageView 
     android:id="@+id/imageView8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView7" 
     android:layout_alignTop="@+id/imageView3" 
     android:src="@drawable/download" /> 

</RelativeLayout> 
</LinearLayout> 
</ScrollView> 
+2

मुझे नहीं लगता कि ऊंचाई आयाम हार्डकोडिंग जाने का तरीका है। –

1
: कोड इस तरह से चला जाता है

जब आप स्क्रॉलव्यू का उपयोग करते हैं, तो आपको पता होना चाहिए कि स्क्रॉलव्यू के बच्चे की ऊंचाई से छोटी स्क्रॉलव्यू की ऊंचाई छोटी हो सकती है।
इस समस्या को हल करने के लिए, आप LinearLayout की ऊंचाई को match_parent में परिभाषित कर सकते हैं, जो स्क्रॉलव्यू का एकमात्र बच्चा है। फिर स्क्रॉलव्यू के बच्चे की ऊंचाई से छोटे स्क्रॉलव्यू की ऊंचाई सुनिश्चित करने के लिए जावा कोड में स्क्रॉल व्यू की ऊंचाई को परिभाषित करें, जैसे scrollView.getChildAt(0).getHeight() - 1;
अपने स्वयं के उत्तर के लिए, 427dp और 548dp जैसे आपके कोड में जादू संख्याओं का उपयोग करने का यह एक अच्छा तरीका नहीं है। जैसे scrollview को fillViewport = "true":

22

सरल समाधान है, सिर्फ एंड्रॉयड जोड़ने

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

<RelativeLayout ....... /> 

</ScrollView> 
+0

यह एक चाल है! धन्यवाद! :) – Marlon