gpt4 book ai didi

android - 滚动后 Recyclerview 截断文本

转载 作者:行者123 更新时间:2023-11-30 01:55:30 25 4
gpt4 key购买 nike

我从数据库中获取数据,将其保存在列表中并将列表传递给自定义的 recyclerView 适配器

问题是滚动后,有些词被截断了:为什么?我怎么能够解决这个问题?

勾选第二张图的charmander和charmeleon,需要代码就问你需要什么

before scrolling

after scrolling: see charmander and cahrmeleon

编辑:适配器:

public class PokedexAdapter extends RecyclerView.Adapter<PokedexAdapter.ViewHolder> {

private List<PokemonBase> mData;
private Context context;
private MainActivity mNavigationDrawerCallbacks;
private View mSelectedView;
private int mSelectedPosition;

public PokedexAdapter(List<PokemonBase> data, Context xontext) {
mData = data;
context = xontext;
}



public void setFumettiCallbacks(MainActivity navigationDrawerCallbacks) {
mNavigationDrawerCallbacks = navigationDrawerCallbacks;
}

@Override
public PokedexAdapter.ViewHolder onCreateViewHolder(final ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.element, viewGroup, false);
final ViewHolder viewHolder = new ViewHolder(v);
viewHolder.itemView.setClickable(true);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, PokemonActivity.class);


intent.putExtra("poke", mData.get(viewHolder.getAdapterPosition()).numero);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {



Pair<View, String> p1 = Pair.create( (View)viewHolder.img, "profile");


ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation((MainActivity)context,(View)viewHolder.img, "profile");


context.startActivity(intent,options.toBundle());}
else
context.startActivity(intent);

}
});



return viewHolder;
}

@Override
public void onBindViewHolder(PokedexAdapter.ViewHolder viewHolder, int i) { //here i set the data

viewHolder.nome.setText(getStringIdentifier(context, mData.get(i).nome));
viewHolder.tipouno.setText(getStringIdentifier(context, mData.get(i).tipo));
viewHolder.tipouno.setTextColor(context.getResources().getColor(getColorIdentifier(context, mData.get(i).tipo)));
if(mData.get(i).tipo2 != null){viewHolder.tipodue.setText(getStringIdentifier(context, mData.get(i).tipo2));
viewHolder.tipodue.setTextColor(context.getResources().getColor(getColorIdentifier(context, mData.get(i).tipo2)));}
else viewHolder.tipodue.setText("");
viewHolder.numero.setText(String.valueOf(mData.get(i).numero));
viewHolder.img.setImageResource(getImageIdentifier(context, mData.get(i).immagine));

}


public void selectPosition(int position) {
mSelectedPosition = position;
notifyItemChanged(position);
}

@Override
public int getItemCount() {
return mData != null ? mData.size() : 0;
}

public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView nome;
public TextView tipouno;
public TextView tipodue;
public TextView numero;
public ImageView img;

public ViewHolder(View itemView) {
super(itemView);
nome = (TextView) itemView.findViewById(R.id.nome);
tipouno = (TextView) itemView.findViewById(R.id.tipoprimo);
tipodue = (TextView) itemView.findViewById(R.id.tiposecondo);
numero = (TextView) itemView.findViewById(R.id.numero);
img = (ImageView) itemView.findViewById(R.id.immagine);
}
}

public static int getStringIdentifier(Context context, String name) {
return context.getResources().getIdentifier(name, "string", context.getPackageName());
}

public static int getImageIdentifier(Context context, String name) {
return context.getResources().getIdentifier(name, "drawable", context.getPackageName());
}

public static int getColorIdentifier(Context context, String name) {
return context.getResources().getIdentifier(name, "color", context.getPackageName());
}

PokemonBase 类:

public class PokemonBase {
int numero;
String nome;
String tipo;
String tipo2;
String immagine;

PokemonBase(){

}

元素.xml :

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="72dp"
xmlns:android="http://schemas.android.com/apk/res/android">



<ImageView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:id="@+id/immagine"
android:maxHeight="40dp"
android:maxWidth="40dp"
android:minHeight="40dp"
android:minWidth="40dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:transitionName="profile"
android:scaleType="centerCrop"/>

<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="16dp" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/nome"
android:layout_marginTop="5dp"
android:transitionName="name"
android:scaleType="centerCrop"/>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="fill_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/tipoprimo" />

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/tiposecondo" />

</LinearLayout>

</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|right">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/numero"
android:layout_marginRight="16dp" />
</LinearLayout>
</LinearLayout>

最佳答案

把你的布局改成这样

<LinearLayout>

<ImageView/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_marginLeft="16dp" >
...
</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|right">
...
</LinearLayout>
</LinearLayout>

我只修改了layout_weightlayout_width,我跳过了那些不需要修改的部分。

关于android - 滚动后 Recyclerview 截断文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32314944/

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