5

प्रदान करना होगा मैं एक PercentFrameLayout इस्तेमाल करने की कोशिश, लेकिन मैं इस त्रुटि संदेश मिलता है:PercentFrameLayout: आप एक layout_width विशेषता

Binary XML file line #: You must supply a layout_width attribute. 

इस एक्सएमएल मैं का उपयोग करें:

<android.support.percent.PercentFrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     app:layout_heightPercent="50%" 
     app:layout_marginLeftPercent="25%" 
     app:layout_marginTopPercent="25%" 
     app:layout_widthPercent="50%"/> 
</android.support.percent.PercentFrameLayout> 

है यह एक बग या क्या यह मेरी गलती है?

+0

यह पैरामीटर के क्रम के अलावा http://developer.android.com/reference/android/support/percent/PercentFrameLayout.html पर उदाहरण जैसा दिखता है, इसलिए मुझे लगता है कि यह सही है। क्या आप वाकई समस्या के साथ विचार हैं? यदि आप उन विचारों को हटाते हैं तो आपका लेआउट सही तरीके से लोड होता है? –

+0

@CoryCharlton हाँ यह डॉक्टर से है और हाँ यह समस्या के साथ दृश्य है। एंड्रॉइड स्टूडियो इसे एक समस्या के रूप में भी हाइलाइट करता है। –

उत्तर

4

layout_width और layout_height गुण अभी भी एक्सएमएल लेआउट विनिर्देशों के कारण आवश्यक है, लेकिन प्रभावी रूप से एक PercentFrameLayout या PercentRelativeLayout में अनदेखी कर रहे हैं।

तुम बस 0dp या wrap_content के मूल्यों को निर्धारित करने के लिए है: जहां भी एक layout_width बारे में बताने की

<ImageView 
    android:layout_height="0dp" 
    android:layout_width="0dp" 
    app:layout_heightPercent="50%" 
    app:layout_marginLeftPercent="25%" 
    app:layout_marginTopPercent="25%" 
    app:layout_widthPercent="50%" /> 

यह layout_weight के साथ एक मानक LinearLayout के उपयोग के समान है।

+0

लेकिन डॉक्टर कहते हैं, 'लेआउट_विड्थ/ऊंचाई निर्दिष्ट करने के लिए लेआउट_विड्थ/ऊंचाई निर्दिष्ट करना आवश्यक नहीं है। –

+0

@ राल्फबर्गमैन यह अजीब है, मैं चौड़ाई/ऊंचाई निर्दिष्ट किए बिना एक्सएमएल संकलित भी नहीं कर सका .. तो मुझे यकीन नहीं है कि क्या दस्तावेज़ सही हैं। – Floern

+0

ऐसा लगता है कि यह जरूरी है - मैंने चौड़ाई/ऊंचाई (कोई अपवाद फेंक दिया नहीं) की कोशिश की है, और केवल 0 डीपी दोनों मानों को सेट करके इसे ठीक से प्रस्तुत करने के लिए प्राप्त कर सकते हैं। – Rachael

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