我有一個回收站視圖,其中顯示的是自定義行,但行未填滿寬度。我已經添加了match_parent寬度,但仍然只是包裝內容。回收站視圖未填滿寬度
我的回收站視圖 - :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.transenigma.iskconapp.events"
tools:showIn="@layout/app_bar_events">
<view
android:id="@+id/recycler_view"
class="android.support.v7.widget.RecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="-16dp"
android:layout_marginRight="-17dp" />
<!--<ProgressBar-->
<!--android:id="@+id/progress_bar"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_centerInParent="true" />-->
</RelativeLayout>
自定義行 - :
<?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="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="80dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
<com.transenigma.iskconapp.BlurImageView
android:id="@+id/myEventImg"
android:layout_width="115dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:layout_gravity="center_vertical"
android:src="@drawable/mayapur" />
<TextView
android:id="@+id/myAboveDay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="-8dp"
android:textSize="50dp"
android:text="Hari"
android:gravity="center_horizontal"/>
<TextView
android:id="@+id/myAboveMonth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textSize="15dp"
android:layout_marginBottom="4dp"
android:text="month"
android:gravity="center_horizontal"/>
</FrameLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/myEventTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#222"
android:textSize="23dp"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="City"
android:textColor="#222"
android:id="@+id/myEventCity"
android:layout_marginLeft="8dp"
android:layout_marginTop="2dp" />
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:textAppearance="?android:attr/textAppearanceSmall"-->
<!--android:text="Date"-->
<!--android:id="@+id/myEventDate"-->
<!--android:textColor="#222"-->
<!--android:layout_marginLeft="8dp"-->
<!--android:layout_marginTop="2dp" />-->
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/myEventObjectId"
android:visibility="invisible"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我的自定義視圖持有人講座:
public class CustomViewHolder extends RecyclerView.ViewHolder{
protected ImageView myEventImg;
protected TextView myEventTitle,myEventCity, myEventObjectId, myAboveDay, myAboveMonth;//,myEventDate
public CustomViewHolder(View view) {
super(view);
this.myEventImg = (ImageView) view.findViewById(R.id.myEventImg);
this.myEventTitle = (TextView) view.findViewById(R.id.myEventTitle);
this.myEventCity = (TextView) view.findViewById(R.id.myEventCity);
//this.myEventDate = (TextView) view.findViewById(R.id.myEventDate);
this.myEventObjectId = (TextView) view.findViewById(R.id.myEventObjectId);
this.myAboveDay = (TextView) view.findViewById(R.id.myAboveDay);
this.myAboveMonth = (TextView) view.findViewById(R.id.myAboveMonth);
}
}
這裏是整個適配器講座:
package com.transenigma.iskconapp;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.parse.GetDataCallback;
import com.parse.ParseException;
import com.parse.ParseFile;
import java.util.List;
public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.CustomViewHolder> {
ProgressDialog progress;
private List<EventsInfo> feedItemList;
private Context mContext;
private int mPreviousPosition = 0;
// OnItemClickListener mItemClickListener;
public MyRecyclerAdapter(Context context, List<EventsInfo> feedItemList) {
this.feedItemList = feedItemList;
this.mContext = context;
}
@Override
public MyRecyclerAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_event_row, null);
CustomViewHolder viewHolder = new CustomViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(MyRecyclerAdapter.CustomViewHolder holder, int position) {
EventsInfo feedItem = feedItemList.get(position);
//Setting text view title
holder.myEventTitle.setText(Html.fromHtml(feedItem.getMyEventTitle()));
holder.myEventCity.setText(Html.fromHtml(feedItem.getMyEventCity()));
//holder.myEventDate.setText(Html.fromHtml(feedItem.getMyEventDate()));
holder.myEventObjectId.setText(feedItem.getEventObjectId());
String[] parts = (feedItem.getMyEventDate()).split(" ");
holder.myAboveDay.setText(parts[0]);
holder.myAboveMonth.setText(parts[1]);
Log.i("Radhe", "Object Id is " + holder.myEventObjectId.getText());
//progress = ProgressDialog.show(mContext, "Please Wait!","We are downloading events", true);
loadImages(feedItem.getImageFile(), holder.myEventImg);
//holder.myEventImg.setImageResource(R.drawable.img);
/*******************Animation**************************/
if (position > mPreviousPosition) {
AnimationUtils.animateSunblind(holder, true);
// AnimationUtils.animate1(holder, true);
// AnimationUtils.animate(holder,true);
} else {
AnimationUtils.animateSunblind(holder, false);
// AnimationUtils.animate1(holder, false);
// AnimationUtils.animate(holder, false);
}
mPreviousPosition = position;
}
private void loadImages(ParseFile thumbnail, final ImageView img) {
if (thumbnail != null) {
thumbnail.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
img.setImageBitmap(bmp);
//progress.dismiss();
} else {
}
}
});
} else {
img.setImageResource(R.drawable.mayapur);
}
}
@Override
public int getItemCount() {
return (null != feedItemList ? feedItemList.size() : 0);
}
public class CustomViewHolder extends RecyclerView.ViewHolder{
protected ImageView myEventImg;
protected TextView myEventTitle,myEventCity, myEventObjectId, myAboveDay, myAboveMonth;//,myEventDate
public CustomViewHolder(View view) {
super(view);
this.myEventImg = (ImageView) view.findViewById(R.id.myEventImg);
this.myEventTitle = (TextView) view.findViewById(R.id.myEventTitle);
this.myEventCity = (TextView) view.findViewById(R.id.myEventCity);
//this.myEventDate = (TextView) view.findViewById(R.id.myEventDate);
this.myEventObjectId = (TextView) view.findViewById(R.id.myEventObjectId);
this.myAboveDay = (TextView) view.findViewById(R.id.myAboveDay);
this.myAboveMonth = (TextView) view.findViewById(R.id.myAboveMonth);
}
}
}
請張貼你的'ViewHolder'類。 –
你想cardview完全覆蓋?我認爲你的BlurImageView不適合是這樣嗎? @pranav shukla –
哎呀,對不起。我的意思是'Adapter'類。實際上,只是'onCreateViewHolder()'方法。 –