0

最初のカスタム アダプターを作成しましたが、これはうまく機能します。それで、アダプターが入力するためのrowlayout.xmlを作成しました。

行は動的ではないため、行よりも長いテキストを配置しようとすると、行は拡張されず、代わりにテキストが切り取られます。(ここで写真を参照してください: http://tinyurl.com/paxdt3a )

これが私のrowLayoutです:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >

    <!--The second line is used for the date of the post-->
    <TextView
        android:id="@+id/secondLine"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="Time and date"
        android:textSize="12sp" />

    <!--The first line is used to the post-->
    <TextView
        android:id="@+id/firstLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/secondLine"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:gravity="center_vertical"
        android:text="Post"
        android:textSize="16sp" />

</RelativeLayout> 

そして、ここに私のアダプターがあります:

public class MyAdapter extends ArrayAdapter<UserPost> {
    private final Context context;
    private final List<UserPost> posts;

    public MyAdapter(Context context, List<UserPost> posts) {
        super(context, R.layout.rowlayout, posts);
        this.context = context;
        this.posts = posts;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.rowlayout, parent, false);

        TextView firstText = (TextView) rowView.findViewById(R.id.firstLine);
        TextView secondText = (TextView) rowView.findViewById(R.id.secondLine);

        //Insert the post
        firstText.setText(posts.get(position).getMessage());
        //Insert the time
        secondText.setText(posts.get(position).getDate());

        return rowView;
    }
}

誰でもこれを解決する方法について何か考えがありますか?

ありがとう!

更新(解決策):

さて、rowlayout.xml にいくつかの変更を加えたところ、最終的にこれが機能するようになりました。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="6dip" >

    <!--The first line is used to the post-->
    <TextView
        android:id="@+id/firstLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:gravity="center_vertical"
        android:text="Post"
        android:textSize="16sp" />

    <!--The second line is used for the date of the post-->
    <TextView
        android:id="@+id/secondLine"
        android:layout_below="@+id/firstLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:ellipsize="marquee"
        android:singleLine="false"
        android:text="Time and date"
        android:textSize="12sp" />

</RelativeLayout> 
4

2 に答える 2

4

あなたには、すべての行の変更に対して特定の行の高さを強制しているという意味がありitem layoutますandroid:layout_height="?android:attr/listPreferredItemHeight"android:layout_height="wrap_content"

于 2014-10-15T10:03:00.763 に答える
0

簡単にできることは、 singleLine プロパティを削除することです

 android:singleLine="false"

または、このようにすることができます

public class MyAdapter extends ArrayAdapter<UserPost> {
private final Context context;
private final List<UserPost> posts;

public MyAdapter(Context context, List<UserPost> posts) {
    super(context, R.layout.rowlayout, posts);
    this.context = context;
    this.posts = posts;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
 LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if(text.length>MAX_LENGTH){
View rowView = inflater.inflate(R.layout.rowlayout1, parent, false);
//....
}else{


    View rowView = inflater.inflate(R.layout.rowlayout, parent, false);

    TextView firstText = (TextView) rowView.findViewById(R.id.firstLine);
    TextView secondText = (TextView) rowView.findViewById(R.id.secondLine);

    //Insert the post
    firstText.setText(posts.get(position).getMessage());
    //Insert the time
    secondText.setText(posts.get(position).getDate());
   }
    return rowView;
  }
}
于 2014-10-15T10:02:34.973 に答える