gpt4 book ai didi

android - SwipeListView : View is messed up. 隐藏内容遍布列表项

转载 作者:行者123 更新时间:2023-11-29 14:49:53 25 4
gpt4 key购买 nike

我是 SwipeListView 库的新手,当滑动列表项之一时,该功能的工作原理如下:

enter image description here

应用程序正在运行,但 View 困惑,以至于隐藏的内容(即滑动列表项后看到的内容)被覆盖在每个列表项的顶部。按照下面的图片,我粘贴了 fragment 代码。

我该如何解决这个问题?

没有 SwipeListView: enter image description here

使用 SwipeListView: enter image description here

import java.util.ArrayList;
import java.util.List;

import android.app.Fragment;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.test.ItemAdapter;
import com.example.test.ItemRow;
import com.example.test.R;
import com.fortysevendeg.swipelistview.BaseSwipeListViewListener;
import com.fortysevendeg.swipelistview.SwipeListView;

public class MyList extends Fragment {

@Override
public void onPause() {
// TODO Auto-generated method stub
super.onPause();

index = list.getFirstVisiblePosition();
}

@Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();

list.setSelectionFromTop(index, 0);
}

ListView list;
int index = 0;
MediaPlayer mp;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedinstanceState)
{

mp=MediaPlayer.create(getActivity(), R.raw.v1);

return inflater.inflate(R.layout.listview, container, false);
}

@Override
public void onStart() {

super.onStart();
list=(ListView)getView().findViewById(R.id.listView1);
list.setAdapter(new MyAdapter(getActivity()));

}
}

class MyAdapter extends BaseAdapter
{
ArrayList<SingleRow> list;
Context context;
ItemAdapter adapter;
List<ItemRow> itemData;

public MyAdapter(Context c) {

context=c;
list=new ArrayList<SingleRow>();
//Initialize them...
int[] images={
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,

};

for(int i=0;i<6;i++)
{
list.add(new SingleRow(images[i]));
}

}

public int convertDpToPixel(float dp) {
DisplayMetrics metrics =context.getResources().getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return (int) px;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub

return list.get(position);
}

@Override
public long getItemId(int position) {

return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

View row=convertView;
MyViewHolder holder=null;
itemData=new ArrayList<ItemRow>();
adapter=new ItemAdapter(context,R.layout.custom_row,itemData);
final SwipeListView swipelistview;

if(row==null)
{
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.list_rows, parent, false);
row.setBackgroundResource(R.drawable.coloria);
holder=new MyViewHolder(row);
SingleRow temp=list.get(position);

holder.imageView.setImageResource(temp.image);

swipelistview = (SwipeListView)row.findViewById(R.id.example_swipe_lv_list);

row.setTag(holder);
}

else
{
swipelistview = (SwipeListView)row.findViewById(R.id.example_swipe_lv_list);
holder=(MyViewHolder)row.getTag();
}

swipelistview.setSwipeListViewListener(new BaseSwipeListViewListener() {
@Override
public void onOpened(int position, boolean toRight) {
}

@Override
public void onClosed(int position, boolean fromRight) {
}

@Override
public void onListChanged() {
}

@Override
public void onMove(int position, float x) {
}

@Override
public void onStartOpen(int position, int action, boolean right) {
Log.d("swipe", String.format("onStartOpen %d - action %d", position, action));
}

@Override
public void onStartClose(int position, boolean right) {
Log.d("swipe", String.format("onStartClose %d", position));
}

@Override
public void onClickFrontView(int position) {
Log.d("swipe", String.format("onClickFrontView %d", position));

swipelistview.openAnimate(position); //when you touch front view it will open

}

public void onClickBackView(int position) {
Log.d("swipe", String.format("onClickBackView %d", position));

swipelistview.closeAnimate(position);//when you touch back view it will close
}

public void onDismiss(int[] reverseSortedPositions) {

}

});

swipelistview.setSwipeMode(SwipeListView.SWIPE_MODE_LEFT);
swipelistview.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL);
swipelistview.setSwipeActionRight(SwipeListView.SWIPE_ACTION_REVEAL);
swipelistview.setOffsetLeft(convertDpToPixel(260f));
swipelistview.setOffsetRight(convertDpToPixel(0f));
swipelistview.setAnimationTime(50);
swipelistview.setSwipeOpenOnLongPress(true);

swipelistview.setAdapter(adapter);

for(int i=0;i<10;i++)
{
itemData.add(new ItemRow("item"+i,context.getResources().getDrawable(R.drawable.ic_launcher) ));

}

Typeface font = Typeface.createFromAsset(holder.textView.getContext().getAssets(), "fonts/OpenSans.ttf");

holder.textView.setTypeface(font);

adapter.notifyDataSetChanged();

return row;
}

class MyViewHolder
{
ImageView imageView;
TextView textView;

MyViewHolder(View v)
{
textView=(TextView)v.findViewById(R.id.textView1);
imageView=(ImageView)v.findViewById(R.id.imageView1);
}
}

class SingleRow
{
int image;
SingleRow(int image)
{
this.image=image;
}
}

}

最佳答案

我现在遇到了同样的问题。这可能是因为您的前端布局的背景是透明的。该库没有隐藏代码,而是有可见的背景。我通过在我的 getView 中隐藏我的“后” View 然后使其在滑动时可见来克服了这个问题。

    mTourneyList.setSwipeListViewListener(new BaseSwipeListViewListener() {
@Override
public void onOpened(int position, boolean toRight) {
LinearLayout li = (LinearLayout) mTourneyList.getChildAt(position - mTourneyList.getFirstVisiblePosition()).findViewById(R.id.back);
li.setVisibility(View.VISIBLE);
}

或者您可以为您的前 View 设置一些背景。

编辑:“位置”参数似乎没有计算屏幕上的行,所以我稍微更改了代码并从“位置”中减去第一个可见位置。

关于android - SwipeListView : View is messed up. 隐藏内容遍布列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21829671/

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