在android中查看带有列表视图项目的Flipper

时间:2015-04-11 22:15:37

标签: android

我想在列表视图中制作视图鳍状肢。所以我创建了一个带有视图鳍状肢的item_layout,它包含两个RelativeLayout; < @ + ID / item_layout_main_content>它显示文本两个图像和< @ + id / item_layout_buttons>它显示了5个按钮,用于发送文本,共享文本,转到详细信息等。除了一件事,一切正常。 一次后,我点击< @ + id / item_layout_main_content>该剂量没有任何按钮,但< @ + id / item_layout_buttons>上的其他按钮;打电话令人惊讶。我不知道为什么!!!

  item_layout.xml
  <?xml version="1.0" encoding="utf-8"?>
  <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/viewfliper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:inAnimation="@anim/slide_down"
android:outAnimation="@anim/slide_up" >

<RelativeLayout
    android:id="@+id/item_layout_main_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="#eee" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_margin="50dp"
        android:text="" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/flower_border_right" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:src="@drawable/flower_border_left" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/item_layout_buttons"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:background="#eee" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" >

        <RelativeLayout
            android:layout_width="50dp"
            android:layout_height="match_parent" >

            <ImageView
                android:id="@+id/iv_back"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerInParent="true"
                android:src="@drawable/back" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp" >

            <ImageView
                android:id="@+id/iv_detail"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerInParent="true"
                android:src="@drawable/detail" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp" >

            <ImageView
                android:id="@+id/iv_share"
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:layout_centerInParent="true"
                android:focusable="true"
                android:paddingLeft="0dp"
                android:src="@drawable/share" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp" >

            <ImageView
                android:id="@+id/iv_sms"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerInParent="true"
                android:focusable="false"
                android:src="@drawable/sms" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp" >

            <ImageView
                android:id="@+id/flavore"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerInParent="true"
                android:src="@drawable/heart_empty" />
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

</ViewFlipper>

slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">

<scale
    android:duration="200"
    android:fromXScale="1.0"
    android:fromYScale="0.0"
    android:pivotX="100%"
    android:pivotY="50%"
    android:interpolator="@android:anim/linear_interpolator"
    android:toXScale="1.0"
    android:toYScale="1.0" />

</set>    

slide_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >

<scale
    android:duration="100"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="100%"
    android:pivotY="50%"
    android:interpolator="@android:anim/linear_interpolator"
    android:toXScale="1.0"
    android:toYScale="0.0" />

</set>

itemAdapter.java

 private static  class ViewHolder {

    public Context context;
    public Ideom ideom;
    public TextView text;
    public ImageView favorite;
    public ImageView sms;
    public ImageView share;
    public ImageView detail;
    public ImageView back;
    public ViewFlipper flipper;

    public void init() {
        text.setText(ideom.getId()+"");
        sms.setOnClickListener(new SendSMS());
        share.setOnClickListener(new ShareText());
        favorite.setOnClickListener(new ToggleFlavore());
        back.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                flipper.showNext();
            }
        });
        if (!ideom.getRate()) {
            favorite.setImageResource(R.drawable.heart_empty);
        } else {
            favorite.setImageResource(R.drawable.heart_fill);
        }
    }

    class SendSMS implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            Log.d("sms", "click");
            if (flipper.getCurrentView().getId() ==        R.id.item_layout_buttons) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.putExtra("sms_body", ideom.getContent());
                intent.setType("vnd.android-dir/mms-sms");
                context.startActivity(intent);

            }

        }
    }

    class ToggleFlavore implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            if (flipper.getCurrentView().getId() ==     R.id.item_layout_buttons) {
                Boolean f=ideom.toggleFavorite();
                if (f) {
                    favorite.setImageResource(R.drawable.heart_fill);
                } else {
                    favorite.setImageResource(R.drawable.heart_empty);
                }
            }
        }
    }

    class ShareText implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            if (flipper.getCurrentView().getId() ==     R.id.item_layout_buttons) {
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.putExtra(android.content.Intent.EXTRA_TEXT,
                        ideom.getContent());
                intent.setType("text/plain");
                context.startActivity(intent);
            }

        }

    }
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    Ideom ideom = ideoms.get(position);
    //if (convertView == null) {
        holder = new ViewHolder();
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.item_layout,null);
        holder.context = context;

        holder.text = (TextView) convertView.findViewById(R.id.textView1);
        holder.favorite = (ImageView)     convertView.findViewById(R.id.flavore);
        holder.sms = (ImageView) convertView.findViewById(R.id.iv_sms);
        holder.share = (ImageView) convertView.findViewById(R.id.iv_share);
        holder.detail = (ImageView)     convertView.findViewById(R.id.iv_detail);
        holder.back = (ImageView) convertView.findViewById(R.id.iv_back);
        holder.flipper = (ViewFlipper)     convertView.findViewById(R.id.viewfliper);
        //holder.flipper.setDisplayedChild(0);
        convertView.setTag(holder);
    //} else {
        //holder = (ViewHolder) convertView.getTag();
        //holder.flipper.setDisplayedChild(0);
    //}
    holder.ideom = ideom;
    //holder.flipper = (ViewFlipper)     convertView.findViewById(R.id.viewfliper);
    holder.init();

    return convertView;
}

MainActivity.java

 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
    ViewFlipper fliper = (ViewFlipper) v.findViewById(R.id.viewfliper);
    if (fliper.getCurrentView().getId() == R.id.item_layout_main_content) {
        fliper.showNext();
        //super.onListItemClick(l, v, position, id);
    }
 }

0 个答案:

没有答案
相关问题