xml文件:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1,2"
android:orientation="vertical"
tools:context=".MainActivity">
<TableRow
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="@+id/ttv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:text="切换卡1" />
<TextView
android:id="@+id/ttv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:onClick="qiehuanka2"
android:text="切换卡2" />
<TextView
android:id="@+id/ttv3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:onClick="qiehuanka3"
android:text="切换卡3" />
</TableRow>
<TextView
android:id="@+id/ttv4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
</TableLayout>
Java代码文件:
package com.example.qiehuanka;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv1,tv2,tv3,tv4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv4 = (TextView) findViewById(R.id.ttv4);
tv1 = (TextView) findViewById(R.id.ttv1);
tv2 = (TextView) findViewById(R.id.ttv2);
tv3 = (TextView) findViewById(R.id.ttv3);
tv1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
tv4.setText("切换卡1");
}
});
tv2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
tv4.setText("切换卡2");
}
});
tv3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
tv4.setText("切换卡3");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
实现效果图: