2009-12-13 28 views
13

मैं एक लेआउट पर काम कर रहा हूं जहां मैं रिलेवेटिव लाइन आइटम के साथ ListView का उपयोग करता हूं। लाइनिटैम स्वयं सही तरीके से प्रदर्शित नहीं हो रहे हैं।एंड्रॉइड का रिलेटिवलाइट टूटा हुआ लगता है

समस्या यह है कि txtVideoDuration TextView नीचे की बजाय लाइन आइटम के शीर्ष पर खींचा जाता है। इस वजह से txtVideoTitle को 0 की ऊंचाई मिलती है। जैसा कि आप एक्सएमएल में देख सकते हैं, txtVideoDuration को ListView के नीचे क्लैंप किया जाना चाहिए।

मेरा लक्ष्य लेआउट को उस ट्यूटोरियल जैसा दिखाना है जो Google ने मुझे दिया था। उदाहरण: http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

मैं एंड्रॉइड 2.0.1 का उपयोग कर रहा हूं। मैंने सूची दृश्य में बाहर संशोधन के साथ उदाहरण लेआउट में भी प्लग किया है और वही व्यवहार होता है।

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="?android:attr/listPreferredItemHeight" 
android:padding="6dip"> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:id="@+id/imgVideoThumbnail" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:minHeight="64dip" 
    android:layout_marginRight="6dip" 
    android:src="@drawable/icon" /> 
<TextView 
    android:id="@+id/txtVideoDuration" 
    android:layout_width="fill_parent" 
    android:layout_height="26dip" 
    android:layout_toRightOf="@+id/imgVideoThumbnail" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:singleLine="true" 
    android:ellipsize="marquee" 
    android:text="0:00:00" /> 
<TextView 
    android:id="@+id/txtVideoTitle" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/imgVideoThumbnail" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_above="@+id/txtVideoDuration" 
    android:layout_alignWithParentIfMissing="true" 
    android:gravity="center_vertical" 
    android:text="[Title]" 
    android:textColor="#FFFFFF" /> 

</RelativeLayout> 

यह सरल मामला काम करता है। यह गतिविधि के लिए रूट एक्सएमएल लेआउट है। शीर्ष पर स्थित बग्गी कोड सूची दृश्य में लाइन आइटम है। ऐसा लगता है कि ListView स्वयं इसे तोड़ रहा है।

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

<ListView 
    android:id="@+id/listVideoCatalog" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 
<TextView 
    android:id="@+id/txtName" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:text="Hello World" /> 
</RelativeLayout> 
</merge> 

यह getView कोड है जो लाइन आइटम को सूची दृश्य में फुलाता है।

static class ViewHolder 
{ 
    TextView txtTitle; 
    ImageView imgThumbnail; 
    TextView txtDuration; 
    Uri videoLocation; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) 
{ 
    ViewHolder holder; 

    if(convertView == null) 
    { 
     LayoutInflater li = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = li.inflate(R.layout.listitem_videolineitem, null); 
     holder = new ViewHolder(); 
     holder.txtDuration = (TextView) convertView.findViewById(R.id.txtVideoDuration); 
     holder.txtTitle = (TextView) convertView.findViewById(R.id.txtVideoTitle); 
     holder.imgThumbnail = (ImageView) convertView.findViewById(R.id.imgVideoThumbnail); 
     convertView.setTag(holder); 
    } 
    else 
    { 
     holder = (ViewHolder) convertView.getTag(); 
    } 

    VideoFile video = this.videos.get(position); 
    holder.txtDuration.setText(millisToTimestamp(video.videoDuration)); 
    holder.txtTitle.setText(video.videoTitle); 

      // Some debugger visual code. 
    holder.txtDuration.setBackgroundColor(Color.GREEN); 
    holder.txtTitle.setBackgroundColor(Color.CYAN); 


    return convertView; 
} 

उत्तर

10

आप अपनी पंक्ति दृश्यों को कैसे बढ़ा रहे हैं जो "छोटी गाड़ी" हैं? क्या आप एक कोड स्निपेट प्रदान कर सकते हैं?

इसके अलावा, android:orientation="vertical"RelativeLayout के लिए मान्य नहीं है।

+0

बस कोड कहा: बस इसे स्पष्ट करना, इस सवाल का जवाब है। मैं Google द्वारा सुझाए गए व्यूहोल्डर पैटर्न का उपयोग कर रहा हूं। –

+0

मैंने रिलेवेटिवआउट से ओरिएंटोन वर्टिकल हटा दिया। उस कोड ने बग में योगदान नहीं दिया लेकिन इसे इंगित करने के लिए धन्यवाद। मैंने इसे हटा दिया। –

+7

li.inflate बदलें (R.layout.listitem_videolineitem, शून्य); li.inflate (R.layout.listitem_videolineitem, अभिभावक, झूठी) के लिए; और देखें कि क्या मदद करता है। – CommonsWare

15

यह उत्तर दिया गया उत्तर के टिप्पणी में उत्तर दिया गया था।

बदलें

li.inflate(R.layout.listitem_videolineitem, null);

को

li.inflate(R.layout.listitem_videolineitem, parent, false);

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