안드로이드의 친척이 깨진 것 같습니다
-
19-09-2019 - |
문제
RelativeLayout 라인 항목이있는 ListView를 사용하는 레이아웃 작업을하고 있습니다. 라인 티 템 자체가 올바르게 표시되지 않습니다.
문제는 txtvideoduration textView가 하단 대신 라인 항목 상단에 그려진다는 것입니다. 이로 인해 txtVideOtitle은 높이 0을 얻습니다. XML에서 볼 수 있듯이 txtVideoDuration은 ListView의 하단에 클램핑되어야합니다.
내 목표는 레이아웃이 Google이 준 튜토리얼과 비슷하게하는 것입니다. 예시: http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html
Android 2.0.1을 사용하고 있습니다. ListView로 수정하여 예제 레이아웃을 연결했으며 동일한 동작이 발생했습니다.
<?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>
이 간단한 케이스가 작동합니다. 이것은 활동의 루트 XML 레이아웃입니다. 상단의 버기 코드는 목록보기의 줄 항목입니다. 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>
이것은 라인 항목을 ListView에 팽창시키는 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;
}
해결책
"버기"인 행보기를 어떻게 팽창시키고 있습니까? 코드 스 니펫을 제공 할 수 있습니까?
또한, android:orientation="vertical"
유효하지 않습니다 RelativeLayout
.
다른 팁
이것은 대답했습니다 논평 받아 들여진 답변. 명확하게하기 위해 이것이 답입니다.
변화
li.inflate(R.layout.listitem_videolineitem, null);
에게
li.inflate(R.layout.listitem_videolineitem, parent, false);