开发者

flipper problem in android

开发者 https://www.devze.com 2023-01-19 05:29 出处:网络
in one xml file i have created some layouts with flipper. main xml file:- <?xml version=\"1.0\" encoding=\"utf-8\"?>

in one xml file i have created some layouts with flipper. main xml file:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ffffff"
android:id="@+id/layout_main">

<ViewFlipper android:id="@+id/details"
    android:layout_width="fill_parent" android:layout_height="fill_parent">


<RelativeLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:id="@+id/facebook_layout">


    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:background="#ffffff"
        android:id="@+id/videolist">
<ImageView android:id="@+id/image1"
                android:layout_width="fill_parent" android:layout_height="wrap_content">
</LinearLayout>



***<LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:background="#ffffff" android:id="@+id/videolistdisplay">
            <ScrollView android:id="@+id/scroll"
                android:layout_width="fill_parent" android:layout_height="wrap_content">
                <LinearLayout android:id="@+id/container"
                    android:orientation="vertical" android:layout_width="fill_parent"
                    android:layout_height="wrap_content"></LinearLayout>
            </ScrollView>***
        </LinearLayout>
    </LinearLayout>

in videolistdisplay i am creating dynamic list with the help of linear layout

private void createListLayOut(Drawable image, String desc, String title,
        final int pos)

{

    final float scale = getBaseContext().getResources().getDisplayMetrics().density;
    arrow_image = new ImageView(this);
    video_title = new TextView(this);
    descDetail = new TextView(this);

    final ImageView thumbImage = new ImageView(this);
    linearContainer = new LinearLayout(this);
    titlewithdesc = new LinearLayout(this);
    line = new LinearLayout(this);

    linearContainer.setId(pos);

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    titlewithdesc.setOrientation(LinearLayout.VERTICAL);
    titlewithdesc.setPadding(1, 1, 1, 1);
    titlewithdesc.setLayoutParams(lp);

    lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    linearContainer.setOrientation(LinearLayout.HORIZONTAL);
    linearContainer.setGravity(Gravity.CENTER_VERTICAL);
    linearContainer.setLayoutParams(lp);
    linearContainer.setPadding(3, 3, 3, 3);

    line.setOrientation(LinearLayout.HORIZONTAL);
    line.setGravity(Gravity.CENTER_VERTICAL);
    line.setLayoutParams(lp);
    line.setPadding(1, 1, 1, 1);
    line.setBackgroundColor(Color.BLACK);

    lp = new LinearLayout.LayoutParams((int) (225 * scale),
            (int) (50 * scale));

    // linearContainer.setBackgroundColor(0);

    thumbImage.setBackgroundDrawable(image);
    thumbImage.setId(pos);

    lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    lp.setMargins(30, 0, 0, 0);

    video_title.setLayoutParams(lp);
    video_title.setLines(2);

    lp = new LinearLayout.LayoutParams((int) (175 * scale),
            (int) (90 * scale));
    lp.setMargins(30, 18, 0, 0);

    descDetail.setLayoutParams(lp);
    descDetail.setLines(3);
    video_title.setTextColor(Color.BLUE);
    video_title.setText(title);
    descDetail.setText(desc);
    descDetail.setTextColor(Color.BLACK);
    descDetail.setPadding(0, 5, 0, 0);

    titlewithdesc.addView(video_title);
    titlewithdesc.addView(descDetail);
    linearContainer.addView(thumbImage);
    linearContainer.addView(titlewithdesc);
    linearContainer.setId(pos);
    video_title.setId(pos);

    linearMain.addView(linearContainer);
    linearMain.addView(line);

    thumbImage.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent myIntent = new Intent(PlayActivity.this,
                    VideoDisplay.class);
            myIntent.putExtra("IndexNumber", v.getId());
            startActivity(myIntent);

        }
    });

}

Problem is this all layout flliping properly but "videolistdisplay" is not going to flip

for slide effect i wrote :

public boolean onTouch(View arg0, MotionEvent arg1) {
    // Get the action that was done on this touch event
    switch (arg1.getAction())
    {
        case MotionEvent.ACTION_DOWN:
        {
            // store the X value when the user's finger was pressed down
            downXValue = arg1.getX();
            break;
        }

        case MotionEvent.ACTION_UP:
        {
            // Get the X value when the user released his/her finger
            float currentX = arg1.getX();           开发者_运维百科 

            // going backwards: pushing stuff to the right
            if (downXValue < currentX)
            {
                // Get a reference to the ViewFlipper
                 ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                 // Set the animation
                  vf.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
                  // Flip!
                  vf.showPrevious();
            }

            // going forwards: pushing stuff to the left
            if (downXValue > currentX)
            {
                // Get a reference to the ViewFlipper
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                 // Set the animation
                 vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
                  // Flip!
                 vf.showNext();
            }
            break;
        }
    }

    // if you return false, these actions will not be recorded
    return true;
}

All of layout working perfectly but videolistdisplay layout display only one time and i can not slide it left or right way.. please tell where i am doing mistake

0

精彩评论

暂无评论...
验证码 换一张
取 消