gpt4 book ai didi

android listview 行占全高

转载 作者:行者123 更新时间:2023-11-29 02:07:56 25 4
gpt4 key购买 nike

我有一个与 ListView 一起使用的相对布局 View 。出于某种原因,即使我已将 layout_height 设置为 wrap_content,布局仍会占用所有空间。结果是列表中的每一行都和屏幕一样高!

我不确定这个 View 有什么问题。它曾经工作得很好。

<?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="wrap_content"
android:background="@drawable/cloudbkg" >

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

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView1"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

</RelativeLayout>

这里是 getView 函数。

public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
try {
final JSONObject holder = getItem(position);
convertView = inflateView(R.layout.dumb);
convertView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
Intent i = new Intent(context, Pending.class);
i.putExtra("id", holder.getString("_id"));
context.startActivity(i);
} catch(Throwable e){
e.printStackTrace();
}
}
});
convertView.setOnLongClickListener(new OnLongClickListener(){
public boolean onLongClick(View v){
try {
final CharSequence[] items = {"Pay", "Delete"};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(holder.getString("service"));
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {

}
}).create().show();
} catch(Throwable e){
e.printStackTrace();
}
return true;
}
});
TextView t = (TextView)convertView.findViewById(R.id.amount);
t.setText(holder.getString("currency") + holder.getString("amount"));
setImg((ImageView)convertView.findViewById(R.id.pic), holder.getJSONObject("to").getString("pic"));
t = (TextView) convertView.findViewById(R.id.time);
t.setText(DateUtils.getRelativeTimeSpanString(holder.getLong("time")*1000, System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_ALL));
t = (TextView) convertView.findViewById(R.id.service);
t.setText(holder.getString("service")); // url, co-ords, or shop

} catch(Throwable e) {
e.printStackTrace();
}
}
return convertView;
}

最佳答案

确保您使用的两张图片不是太大。

关于android listview 行占全高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8931594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com