gpt4 book ai didi

android - 回收站 View 未填充宽度

转载 作者:行者123 更新时间:2023-11-29 14:18:33 27 4
gpt4 key购买 nike

我有一个回收站 View ,我在其中显示了自定义行,但该行未填满宽度。我已经添加了 match_parent 宽度,但它仍然只是包装内容。

我的回收站 View -:

<?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>

我的自定义 View 持有者类-:

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);
}
}

这是整个 Adapter 类:

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);
}
}

}

最佳答案

这是因为你添加了Adapter下的onCreateViewHolder如下

 @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 MyRecyclerAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_event_row, parent, false);
CustomViewHolder viewHolder = new CustomViewHolder(view);
return viewHolder;
}

关于android - 回收站 View 未填充宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35216125/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com