我写了一个小应用程序,它显示了几张安卓卡.但我希望能够在卡片的顶部设置颜色和标题,如下图所示,到目前为止,我还没有在网上找到任何信息如何执行此操作.所以一些帮助会很棒:-)
(到目前为止,我的代码没有完成上述任务,我的代码只生成常规的所有白色卡片视图)
我的代码到目前为止如下:
CardAdapter.java
public class CardAdapter extends RecyclerView.Adapter
MainActivity.java
public class MainActivity extends ActionBarActivity implements SwipeRefreshLayout.OnRefreshListener {
@InjectView(R.id.mainView)
RecyclerView mRecyclerView;
@InjectView(R.id.refreshContainer)
SwipeRefreshLayout refreshLayout;
private LinearLayoutManager mLayoutManager;
private CardAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
mRecyclerView.setHasFixedSize(true);
refreshLayout.setOnRefreshListener(this);
TypedValue tv = new TypedValue();
int actionBarHeight = 0;
if (getTheme().resolveAttribute(R.attr.actionBarSize,tv,true)) {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
refreshLayout.setProgressViewEndTarget(true,actionBarHeight);
mAdapter = new CardAdapter();
mRecyclerView.setAdapter(mAdapter);
// use a linear layout manager
mLayoutManager = new GridLayoutManager(this,1);
mRecyclerView.setLayoutManager(mLayoutManager);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button,so long
// as you specify a parent activity in AndroidManifest.xml.
return super.onOptionsItemSelected(item);
}
@Override
public void onRefresh() {
mAdapter.clear();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
refreshLayout.setRefreshing(false);
}
},2500);
}
}
activity_main.xml中
item_cardview.xml:
我给你的唯一改变是,card_view:cardCornerRadius =“8dp”>并删除了imageview(不再需要)
闪卡无法填充到卡的一半的屏幕截图:
最佳答案
我相信这是(几乎)确切的布局你想要的.这是非常不言自明的,但可以随意询问是否有不清楚的事情.
原文链接:https://www.f2er.com/android/431200.html
我已经用imageView替换了你的mapFragment(大概)以减少并发症.
更新:由于问题现在解决臭名昭着的“圆角”问题,这实际上是设计的.是的,这是一个很大的缺陷.但是解决方案(在文档Here中给出)将是使用card_view:cardPreventCornerOverlap =“false”属性(我认为它没有任何好处,因为它只是使卡片正方形).
请参阅以下问题以获得对此问题的良好参考:
Appcompat CardView and Picasso no rounded Corners
Make ImageView fit width of CardView