我有一個圖像視圖,我想創建兩個按鈕,使用戶能夠轉到下一個或上一個圖像。當用戶點擊圖像時,按鈕應該出現,在第二次點擊時,按鈕應該消失。如何去做這件事?製作按鈕在圖像視圖上出現和消失
1
A
回答
6
好在目前我工作的同樣的事情,這裏是我的代碼進行修改以滿足您的需求
XML代碼
<?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>
主代碼
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
非常感謝。 U just rock – pradeep 2011-03-17 10:18:06
+0
歡迎,如果您的查詢已解決,您可以正確標記答案,以便其他人會認爲它有用 – ingsaurabh 2011-03-17 10:44:06
+0
我做到了。隨着投票 – pradeep 2011-03-17 10:54:21
能你展示你有什麼嘗試,但我的意思是你的代碼? – ingsaurabh 2011-03-17 06:52:00
我還沒有嘗試過任何東西。只是想要一些指示這樣做。 – pradeep 2011-03-17 06:53:27