像Paytm一样的水平RecyclerView

时间:2016-09-28 10:35:52

标签: android android-recyclerview paytm

我必须实现一个自定义水平-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if([FinalArrayCategory count]>0) { return [[[FinalArrayCategory objectAtIndex:0] objectForKey:@"food_list"] count]; } else { return 0; } } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if([FinalArrayCategory count]>0) { return [[FinalArrayCategory valueForKey:@"menu_name"] count]; } else { return 0; } } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *sectionName; sectionName =[[FinalArrayCategory valueForKey:@"menu_name"] objectAtIndex:section]; return sectionName; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; MenuListCELL *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell.lblpice.text=[[[[FinalArrayCategory objectAtIndex:indexPath.section]objectForKey:@"food_list"] valueForKey:@"food_name"]objectAtIndex:indexPath.row]; // cell.lblType.text=[[FinalArrayCategory valueForKey:@"category_name"] objectAtIndex:indexPath.row]; // cell.lblBonus.text=[[FinalArrayCategory valueForKey:@"food_bonus"] objectAtIndex:indexPath.section]; // cell.lblFoodName.text=[[FinalArrayCategory valueForKey:@"menu_name"] objectAtIndex:indexPath.section]; // // NSString *pickURL=[[FinalArrayCategory valueForKey:@"food_image"] objectAtIndex:indexPath.section]; // [cell.lblImage sd_setImageWithURL:[NSURL URLWithString:pickURL] placeholderImage:[UIImage imageNamed:@"itemplaceholder.jpg"] options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) { // } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { // }]; return cell; } ,其顶部有标题(标题),RecyclerView末尾有一个部分(全部见)。

我创建了一个带有页眉和页脚的RecyclerView,但我希望有一个右侧部分(请参阅全部),其中onclick事件我希望触发一些事件。

在Paytm App中,它已实现

我希望得到如下结果

Can the value of information gain be negative?

1 个答案:

答案 0 :(得分:2)

这会给你一个想法

  

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp">

<android.support.v7.widget.RecyclerView
    android:id="@+id/verticalScrollRecyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</android.support.v7.widget.RecyclerView></RelativeLayout>

<强> vertical_scroll_single_entry.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:weightSum="1"
android:gravity="center_vertical">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

</android.support.v7.widget.RecyclerView>

<Button
    android:id="@+id/selectAllButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="See All >>"
    android:textAllCaps="false"/></LinearLayout>

垂直滚动条的自定义适配器类

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.CustomViewHolder> {


private Context context;
private ArrayList arrayList;
private LayoutInflater layoutInflater;

public CustomAdapter(Context context, ArrayList arrayList) {
    this.context = context;
    this.layoutInflater = LayoutInflater.from(context);
    this.arrayList = arrayList;
}

@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = layoutInflater.inflate(R.layout.vertical_scroll_single_entry, parent, false);
    return new CustomViewHolder(view);
}

@Override
public void onBindViewHolder(CustomViewHolder holder, int position) {
    //initialise values to views inside holder at runtime
    holder.recyclerView.setAdapter(new CustomAdapterTwo(context, arrayList));
    holder.recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
    holder.recyclerView.setHasFixedSize(true);
}

@Override
public int getItemCount() {
    return arrayList.size();
}

class CustomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    RecyclerView recyclerView;
    Button selectAllButton;

    public CustomViewHolder(View itemView) {
        super(itemView);

        recyclerView = (RecyclerView) itemView.findViewById(R.id.recyclerView);

        selectAllButton = (Button) itemView.findViewById(R.id.selectAllButton);
        selectAllButton.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        Toast.makeText(context, "Select All At : " + String.valueOf(getLayoutPosition()), Toast.LENGTH_SHORT).show();
    }
}}

水平适配器单一条目文件recycler_view_single_item.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="match_parent" android:gravity="center_horizontal">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Price"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Remove this button \n and put image view"
    android:textAllCaps="false"/></LinearLayout>

水平回收站视图适配器类

public class CustomAdapterTwo extends RecyclerView.Adapter<CustomAdapterTwo.CustomViewHolder> {
private Context context;
private ArrayList arrayList;
private LayoutInflater layoutInflater;

public CustomAdapterTwo(Context context, ArrayList arrayList) {
    this.context = context;
    this.arrayList = arrayList;
    this.layoutInflater = LayoutInflater.from(context);
}

@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = layoutInflater.inflate(R.layout.recycler_view_single_item, parent, false);

    return new CustomViewHolder(view);
}

@Override
public void onBindViewHolder(CustomViewHolder holder, int position) {



}

@Override
public int getItemCount() {
    return arrayList.size();
}

class CustomViewHolder extends RecyclerView.ViewHolder {

    public CustomViewHolder(View itemView) {
        super(itemView);
    }
}}

您的主要活动类

public class MainActivity extends AppCompatActivity {
private RecyclerView verticalScrollRecyclerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initialiseView();

}

private void initialiseView() {

    verticalScrollRecyclerView = (RecyclerView) findViewById(R.id.verticalScrollRecyclerView);

    ArrayList<String> stringArrayList = new ArrayList<>();

    stringArrayList.add("One");
    stringArrayList.add("Two");
    stringArrayList.add("Three");
    stringArrayList.add("Four");
    stringArrayList.add("Five");
    stringArrayList.add("Six");
    stringArrayList.add("Seven");
    stringArrayList.add("Eight");
    stringArrayList.add("Nine");
    stringArrayList.add("Ten");



    //setting adapter and layout manager to recyclerView
    verticalScrollRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    verticalScrollRecyclerView.setAdapter(new CustomAdapter(this, stringArrayList));
    verticalScrollRecyclerView.setHasFixedSize(true);

}}

看起来像

enter image description here