嗨,我目前正在设计我的用户信息表单的样式,我可以问别人如何实现当我按下某个 imageview 按钮时,我的视图将展开,反之亦然。
示例屏幕截图:
如果不展开。
按向下箭头展开时:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import com.yoesuv.demorecyclerview.adapter.CardViewAdapter;
public class MainActivity extends AppCompatActivity {
private String[] dataset;
private RecyclerView.Adapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dataset = getResources().getStringArray(R.array.android);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if(getSupportActionBar()!=null){
getSupportActionBar().setElevation(5);
}
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new CardViewAdapter(dataset);
mRecyclerView.setAdapter(adapter);
}
}
CardviewAdapter.java
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.yoesuv.demorecyclerview.R;
public class CardViewAdapter extends RecyclerView.Adapter<CardViewAdapter.ViewHolder> {
private String[] dataset;
public CardViewAdapter(String[] dataset){
this.dataset = dataset;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemLayout = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_row, null);
return new ViewHolder(itemLayout);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.tV.setText(dataset[position]);
}
@Override
public int getItemCount() {
return dataset.length;
}
public static class ViewHolder extends RecyclerView.ViewHolder{
public TextView tV;
public ViewHolder(View itemView) {
super(itemView);
tV = (TextView) itemView.findViewById(R.id.textView_data);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), tV.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
感谢任何帮助。