开发者

making buttons appear and disappear on an image view

I have an image view, i want to to create two buttons which will enable users to go to next or p开发者_如何学JAVArevious image. When a user taps the image , the buttons should appear and on the second tap , the button should disappear. How to go about doing this ?


Fortunately currently I am working on the same thing and here is my code modify it to suit your needs

xml code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
    <LinearLayout
        android:id="@+id/button_holder"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:visibility="gone">
        <Button
            android:id="@+id/buy"
            android:text="Buy"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <Button
            android:id="@+id/cancel"
            android:text="Cancel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>
</RelativeLayout>

Main code

Button mBuy = (Button) findViewById(R.id.buy);
    mBuy.setOnClickListener(new OnClickListener()
    {           
        @Override
        public void onClick(View v)
        {

        }
    });

    Button mCancel = (Button) findViewById(R.id.cancel);
    mCancel.setOnClickListener(new OnClickListener()
    {           
        @Override
        public void onClick(View v)
        {
            finish();
        }
    });
    ImageView mView = (ImageView) findViewById(R.id.image);
    mView.setOnClickListener(new OnClickListener()
    {           
        @Override
        public void onClick(View v)
        {
            LinearLayout mLayout = (LinearLayout) findViewById(R.id.button_holder);
            if(!isVisible)
            {
                isVisible = true;
                mLayout.setVisibility(View.VISIBLE);
            }
            else
            {
                isVisible = false;
                mLayout.setVisibility(View.GONE);
            }
        }
    });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜