Android的RelativeLayout的似乎打破 [英] Android's RelativeLayout seems broken

查看:97
本文介绍了Android的RelativeLayout的似乎打破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个布局,我使用带有RelativeLayout的行项目的ListView。该lineItems的本身无法正确显示。

的问题是,txtVideoDuration TextView的绘制在订单项而不是底部的顶部。这是因为txtVideoTitle得到一个0高度,你可以在XML看到txtVideoDuration应该是夹到ListView的底部。

我的目标是使布局类似,谷歌给我的教程。例如:<一href="http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html">http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

我使用的是Android 2.0.1。我甚至插在例如布局进行改造成ListView和相同的行为发生。

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT; RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =机器人:ATTR /列表preferredItemHeight
机器人:填充=6dip&GT;
&LT; ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:ID =@ + ID / imgVideoThumbnail
机器人:layout_alignParentTop =真
机器人:layout_alignParentBottom =真
机器人:=了minHeight64dip
机器人:layout_marginRight =6dip
机器人:SRC =@可绘制/图标/&GT;
&LT;的TextView
机器人:ID =@ + ID / txtVideoDuration
机器人:layout_width =FILL_PARENT
    机器人:layout_height =26dip
    机器人:layout_toRightOf =@ + ID / imgVideoThumbnail
    机器人:layout_alignParentBottom =真
    机器人:layout_alignParentRight =真
    机器人:单线=真
    机器人:ellipsize =金字招牌
机器人:文本=0:00:00/&GT;
&LT;的TextView
机器人:ID =@ + ID / txtVideoTitle
机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_toRightOf =@ + ID / imgVideoThumbnail
    机器人:layout_alignParentRight =真
    机器人:layout_alignParentTop =真
    机器人:layout_above =@ + ID / txtVideoDuration
    机器人:layout_alignWithParentIfMissing =真
    机器人:重力=center_vertical
机器人:文本=[标题]
机器人:文字颜色=#FFFFFF/&GT;

&LT; / RelativeLayout的&GT;
 

这个简单的情况下工作。这是为活动的根XML布局。马车code上方是在列表视图中的行项目。看来,ListView控件本身是打破了。

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT;合并的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android&GT;
&LT; RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT&GT;

&LT;的ListView
机器人:ID =@ + ID / listVideoCatalog
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/&GT;
&LT;的TextView
机器人:ID =@ + ID / txtName的
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentBottom =真
机器人:文本=Hello World的/&GT;
&LT; / RelativeLayout的&GT;
&LT; /合并&GT;
 

这是getView code行项膨胀到ListView中。

 静态类ViewHolder
{
TextView的txtTitle;
ImageView的imgThumbnail;
TextView的txtDuration;
乌里videoLocation;
}

@覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup)
{
ViewHolder持有人;

如果(convertView == NULL)
{
LayoutInflater力=(LayoutInflater)this.getContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。
convertView = li.inflate(R.layout.listitem_videolineitem,NULL);
持有人=新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(保持器);
}
	其他
{
支架=(ViewHolder)convertView.getTag();
}

VideoFile视频= this.videos.get(位置);
holder.txtDuration.setText(millisToTimestamp(video.videoDuration));
holder.txtTitle.setText(video.videoTitle);

            //一些调试可视code。
holder.txtDuration.setBackgroundColor(Color.GREEN);
holder.txtTitle.setBackgroundColor(Color.CYAN);


返回convertView;
}
 

解决方案

你是如何夸大你行的观点是越野车?你能提供一个code段?

此外,机器人:方向=垂直不适用于 RelativeLayout的

I'm working on a layout where I use a ListView with RelativeLayout line items. The lineitems themselves are not displaying correctly.

The issue is that the txtVideoDuration TextView is drawn at the top of the line item instead of the bottom. Because of this the txtVideoTitle gets a height of 0. As you can see in the XML the txtVideoDuration is supposed to be clamped to the bottom of the ListView.

My goal is to have the layout resemble the tutorial that google gave me. Example: http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

I'm using Android 2.0.1. I've even plugged in the example layout with out modification into the ListView and the same behavior happens.

<?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>

This simple case works. This is the root XML layout for the activity. The buggy code at the top is the line items in the list view. It seems that the ListView itself is breaking it.

<?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>

This is the getView Code that inflates the line item into the ListView.

    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;
}

解决方案

How are you inflating your row views that are "buggy"? Can you provide a code snippet?

Also, android:orientation="vertical" is not valid for RelativeLayout.

这篇关于Android的RelativeLayout的似乎打破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆