如何操作取景器?
正如我的下面的代码所示,按钮五和六显示标题为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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您可以为不同布局中的两个按钮赋予相同的标签,并且每当翻转移动时(可以通过触摸事件获取)将焦点更改为具有相同标签的按钮。
谢谢
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