1

由于某种原因,我无法查看包含在 row.xml 文件中的列表视图按钮。

这是我正在使用的 main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent">
<ListView 
    android:id="@+id/friendsListView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/>
</LinearLayout>

row.xml 如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="2dp">

 <ImageView android:id="@+id/imgIcon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:layout_marginRight="10dp"
    android:contentDescription="@string/fbUserPic"/>

 <TextView android:id="@+id/txtTitle"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:textStyle="normal"
    android:textSize="12dp"
    android:textColor="#FFFFFF"/>

 <Button android:id="@+id/btnPost"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="@string/fbbtnPost"
    android:focusable="false"/>
 </LinearLayout>

以下是我正在使用的自定义适配器中的 getView 覆盖

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    View row = convertView;
    FriendRowHolder friendHolder = null;

    if (row == null) 
    {
          LayoutInflater inflater = ((Activity)objContext).getLayoutInflater();
          row = inflater.inflate(layoutResourceId, parent, false);

          friendHolder = new FriendRowHolder();
          friendHolder.txtTitle = (TextView) row.findViewById(R.id.txtTitle);
          friendHolder.imgIcon = (ImageView) row.findViewById(R.id.imgIcon);
          friendHolder.btnPost = (Button) row.findViewById(R.id.btnPost);

          row.setTag(friendHolder);
    }
    else
    {
        friendHolder = (FriendRowHolder)row.getTag();
    }

    Friend objFriend = lstFriends.get(position);
    friendHolder.txtTitle.setText(objFriend.GetName());
    friendHolder.imgIcon.setImageBitmap(loadBitmap(objFriend.GetPictureURL()));
    friendHolder.btnPost.setText("Hi");

    return row;
}
4

1 回答 1

0

问题在于按钮放置在屏幕右侧太多。我只需要将按钮向左移动即可使其出现。

于 2012-12-18T21:09:21.663 回答