android动态图像放置刻度线并选择一个图像

时间:2016-09-01 09:29:31

标签: java android

我想选择一个图像,如单选按钮,并在该图像上添加刻度线。我该怎么做。我在这里添加我的适配器类和xml文件

这是我的适配器类。

public class StarCountAdapter extends RecyclerView.Adapter<StarCountAdapter.StarCountHolder> {
    Context context;
    LayoutInflater inflater;
    List<StarCount> starCounts = new ArrayList<>();

    public StarCountAdapter(Context context, List<StarCount> starCounts) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.starCounts = starCounts;
    }
    @Override
    public StarCountHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.star_count_row,parent,false);
        return new StarCountHolder(view);
    }
    @Override
    public void onBindViewHolder(StarCountHolder holder, int position) {
        StarCount model = starCounts.get(position);
        Picasso.with(context)
                .load("http://"+model.getImagePath())
                .into(holder.starImage);
        holder.actorName.setText(model.getName());
        holder.counts.setText(""+model.getCount());
    }
    @Override
    public int getItemCount() {
        return starCounts.size();
    }    
    public class StarCountHolder extends RecyclerView.ViewHolder {
        ImageView starImage;
        TextView actorName,counts;
        public StarCountHolder(View itemView) {
            super(itemView);
            starImage = (ImageView) itemView.findViewById(R.id.starCountIv);
            actorName = (TextView) itemView.findViewById(R.id.acterName);
            counts = (TextView) itemView.findViewById(R.id.counts);
        }
    }
}

这是我的star_count_row.xml文件。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">
    <ImageView
        android:id="@+id/starCountIv"
        android:layout_width="match_parent"
        android:layout_height="175dp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="120dp"
        android:orientation="vertical">
        <TextView
            android:id="@+id/acterName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#000" />
        <TextView
            android:id="@+id/counts"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#000" />
    </LinearLayout>
</RelativeLayout>

谢谢。

1 个答案:

答案 0 :(得分:0)

在此处创建自定义单选按钮链接,您将获得答案

Adding custom radio buttons in android