正如我的下面的代码显示,一旦按钮五和六显示titlesfourq1。 我点击buttonfive它将显示numten然后如果我点击numten它将显示numsix。但是如何在相同的布局中显示带有numten的numsix?
<?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;
}
}
};
}
答案 0 :(得分:1)
为此你可以为不同布局的两个按钮提供相同的标签,每当翻转移动(可以通过触摸事件获得)时,将焦点改为具有相同标签的按钮。
感谢名单