如何操作取景器?

发布于 2024-12-08 09:40:10 字数 5412 浏览 1 评论 0原文

正如我的下面的代码所示,按钮五和六显示标题为fourq1。 我单击按钮五,它将显示 numten,然后如果我单击 numten,它将显示 numsix。但是如何在同一布局中显示 numsix 和 numten 呢?

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

<AbsoluteLayout android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <Button android:background="@drawable/buttonsix" android:id="@+id/radio0"
        android:layout_width="40dip" android:layout_height="40dip" android:layout_marginTop="50dip" android:layout_x="20dip" android:layout_y="55dip">
    </Button>

        <Button android:background="@drawable/buttonfive" android:id="@+id/radio1"
        android:layout_width="40dip" android:layout_height="40dip" android:layout_marginTop="150dip" android:layout_x="200dip" android:layout_y="200dip">
    </Button>




</AbsoluteLayout>

    <ViewFlipper android:id="@+id/ViewFlipper01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_x="20dip">
        <!--adding views to ViewFlipper-->

        <TextView
    android:id="@+id/title"
    android:textStyle="bold" 
    android:textColor="#ffffff"
    android:gravity="center_vertical|center_horizontal" 
    android:text="@string/titlesfourq1" android:layout_height="wrap_content" android:layout_y="10dip" android:layout_x="5dip" android:textSize="20dip" android:layout_width="340dp"/>

        <Button android:text="@string/numten" android:id="@+id/number" android:textStyle="bold"  android:background="@color/translucent_black" android:textColor="#ffffff"
        android:layout_width="40dip" android:layout_height="40dip" android:layout_marginTop="150dip" android:layout_x="200dip" android:layout_y="200dip">
    </Button>

            <Button android:text="@string/numsix" android:id="@+id/number" android:textStyle="bold"  android:background="@color/translucent_black" android:textColor="#ffffff"
        android:layout_width="40dip" android:layout_height="40dip" android:layout_marginTop="150dip" android:layout_x="200dip" android:layout_y="200dip">
    </Button>



        <TextView android:id="@+id/TextView02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Second view is now displayed"></TextView>
        <TextView android:id="@+id/TextView03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Third view is now displayed"></TextView>
    </ViewFlipper>

</AbsoluteLayout>

爪哇:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class Sfourq1 extends Activity {

    Button RB0;
    Button RB1;
    Button RB2;
    ViewFlipper VF;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sfourq1);

        /*
         * Find the views declared in main.xml.
         */
        RB0 = (Button) findViewById(R.id.radio0);
        RB1 = (Button) findViewById(R.id.radio1);
        RB2 = (Button) findViewById(R.id.number);
        VF = (ViewFlipper) findViewById(R.id.ViewFlipper01);

        /*
         * Set a listener that will listen for clicks on the radio buttons and
         * perform suitable actions.
         */
        RB0.setOnClickListener(button_one);
        RB1.setOnClickListener(button_two);
        RB2.setOnClickListener(button_test);

    }

    /*
     * Define a OnClickListener that will change which view that is displayed by
     * the ViewFlipper
     */
    private OnClickListener button_one = new OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.radio0:
                VF.setDisplayedChild(0);
                Button button = (Button) v;
                button.setVisibility(View.INVISIBLE);

                break;

            }
        }
    };


    private OnClickListener button_two = new OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.radio1:
                VF.setDisplayedChild(1);
                Button button = (Button) v;
                button.setVisibility(View.INVISIBLE);

                break;


            }
        }
    };



    private OnClickListener button_test = new OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.number:
                VF.setDisplayedChild(2);
                Button button = (Button) v;
                button.setVisibility(View.INVISIBLE);
                Intent StartGameIntent = new Intent(Sfourq1.this,Home.class);
                startActivity(StartGameIntent);
                break;

                }
            }
        };
}

As my below codes shows that once button five and six shows with the titlesfourq1.
I click buttonfive it will show numten then if I click numten it will show numsix. But how do I show numsix with numten in the same layout?

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

<AbsoluteLayout android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <Button android:background="@drawable/buttonsix" android:id="@+id/radio0"
        android:layout_width="40dip" android:layout_height="40dip" android:layout_marginTop="50dip" android:layout_x="20dip" android:layout_y="55dip">
    </Button>

        <Button android:background="@drawable/buttonfive" android:id="@+id/radio1"
        android:layout_width="40dip" android:layout_height="40dip" android:layout_marginTop="150dip" android:layout_x="200dip" android:layout_y="200dip">
    </Button>




</AbsoluteLayout>

    <ViewFlipper android:id="@+id/ViewFlipper01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_x="20dip">
        <!--adding views to ViewFlipper-->

        <TextView
    android:id="@+id/title"
    android:textStyle="bold" 
    android:textColor="#ffffff"
    android:gravity="center_vertical|center_horizontal" 
    android:text="@string/titlesfourq1" android:layout_height="wrap_content" android:layout_y="10dip" android:layout_x="5dip" android:textSize="20dip" android:layout_width="340dp"/>

        <Button android:text="@string/numten" android:id="@+id/number" android:textStyle="bold"  android:background="@color/translucent_black" android:textColor="#ffffff"
        android:layout_width="40dip" android:layout_height="40dip" android:layout_marginTop="150dip" android:layout_x="200dip" android:layout_y="200dip">
    </Button>

            <Button android:text="@string/numsix" android:id="@+id/number" android:textStyle="bold"  android:background="@color/translucent_black" android:textColor="#ffffff"
        android:layout_width="40dip" android:layout_height="40dip" android:layout_marginTop="150dip" android:layout_x="200dip" android:layout_y="200dip">
    </Button>



        <TextView android:id="@+id/TextView02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Second view is now displayed"></TextView>
        <TextView android:id="@+id/TextView03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Third view is now displayed"></TextView>
    </ViewFlipper>

</AbsoluteLayout>

Java:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class Sfourq1 extends Activity {

    Button RB0;
    Button RB1;
    Button RB2;
    ViewFlipper VF;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sfourq1);

        /*
         * Find the views declared in main.xml.
         */
        RB0 = (Button) findViewById(R.id.radio0);
        RB1 = (Button) findViewById(R.id.radio1);
        RB2 = (Button) findViewById(R.id.number);
        VF = (ViewFlipper) findViewById(R.id.ViewFlipper01);

        /*
         * Set a listener that will listen for clicks on the radio buttons and
         * perform suitable actions.
         */
        RB0.setOnClickListener(button_one);
        RB1.setOnClickListener(button_two);
        RB2.setOnClickListener(button_test);

    }

    /*
     * Define a OnClickListener that will change which view that is displayed by
     * the ViewFlipper
     */
    private OnClickListener button_one = new OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.radio0:
                VF.setDisplayedChild(0);
                Button button = (Button) v;
                button.setVisibility(View.INVISIBLE);

                break;

            }
        }
    };


    private OnClickListener button_two = new OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.radio1:
                VF.setDisplayedChild(1);
                Button button = (Button) v;
                button.setVisibility(View.INVISIBLE);

                break;


            }
        }
    };



    private OnClickListener button_test = new OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.number:
                VF.setDisplayedChild(2);
                Button button = (Button) v;
                button.setVisibility(View.INVISIBLE);
                Intent StartGameIntent = new Intent(Sfourq1.this,Home.class);
                startActivity(StartGameIntent);
                break;

                }
            }
        };
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2024-12-15 09:40:12

为此,您可以为不同布局中的两个按钮赋予相同的标签,并且每当翻转移动时(可以通过触摸事件获取)将焦点更改为具有相同标签的按钮。

谢谢

for this you can give same tag to both buttons in different layout and whenever flip moves(can get by touch event)change focus to button with same tag.

thanx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文