我正在使用TextView
下的android.support.v7.widget.CardView。但是,每當我嘗試設置長文本時,TextView
都沒有給出完整的結果。如何在CardView下的TextView中的下一行自動對齊長文本
List<User> userList = new ArrayList<>();
userList.add(new User(R.mipmap.ic_launcher,
"Amit", "9988776655",
"[email protected]@[email protected]@[email protected]@sonevalley.com"));
這是我的Java代碼(作爲一個例子),這表明在這樣的應用程序: for this first one 'Amit'。
如何解決這個問題?如果文字很長,則會自動將其設置爲下一行。
這裏是我的全部Cardview.xml
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<android.support.v7.widget.CardView
android:id="@+id/cvSingleUser"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp">
<ImageView
android:id="@+id/ivProfilePic"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="16dp" />
<TextView
android:id="@+id/tvProfileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_toRightOf="@id/ivProfilePic" />
<TextView
android:id="@+id/tvPhoneNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvProfileName"
android:layout_toRightOf="@id/ivProfilePic" />
<TextView
android:id="@+id/tvEmailId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:scrollHorizontally="true"
android:layout_below="@id/tvPhoneNumber"
android:layout_toRightOf="@id/ivProfilePic" />
</RelativeLayout>
</android.support.v7.widget.CardView>
,這是java代碼的快照:Java Snap Shot
這是Java完整的代碼
public class AllUsersAdapter extends RecyclerView.Adapter<AllUsersAdapter.UserViewHolder>{
private List<MainActivity.User> userList;
private Context context;
public AllUsersAdapter(List<MainActivity.User> userList, Context context) {
this.userList = userList;
this.context = context;
}
@Override
public UserViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.single_cardview_layout, null);
UserViewHolder userViewHolder = new UserViewHolder(view);
return userViewHolder;
}
@Override
public void onBindViewHolder(UserViewHolder holder, int position) {
MainActivity.User user = userList.get(position);
String a=user.getEmailId().toString();
holder.tvProfileName.setText(user.getProfileName());
holder.tvPhoneNumber.setText(user.getPhoneNumber());
holder.tvEmailId.setText(a);
}
@Override
public int getItemCount() {
return userList.size();
}
public static class UserViewHolder extends RecyclerView.ViewHolder {
TextView tvProfileName;
TextView tvPhoneNumber;
TextView tvEmailId;
public UserViewHolder(View itemView) {
super(itemView);
tvProfileName = (TextView) itemView.findViewById(R.id.tvProfileName);
tvPhoneNumber = (TextView) itemView.findViewById(R.id.tvPhoneNumber);
tvEmailId = (TextView) itemView.findViewById(R.id.tvEmailId);
}
}
}
謝謝。
這個文本將被動態地添加。我在這裏設置只是爲了看到結果 –