嗨程序員我很尊重你們所有人。 即時通訊在這裏新的android編程。在textview中的android引力不起作用
即時通訊工具我的單選按鈕與我的文本視圖中的重力功能通過對齊他們從中心,左側和右側的問題。
我的API爲23
和IM下面這個教程youtube tutorial,但我的工作不
package com.example.testavd;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity implements OnCheckedChangeListener {
TextView txtV;
RadioGroup rg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtV = (TextView) findViewById(R.id.textOut);
rg = (RadioGroup) findViewById(R.id.rdG);
rg.setOnCheckedChangeListener(this);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
txtV.setText("boom");
}
});
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId){
case R.id.rbCenter:
txtV.setGravity(Gravity.CENTER);
break;
case R.id.rbLeft:
txtV.setGravity(Gravity.LEFT);
break;
case R.id.rbRight:
txtV.setGravity(Gravity.RIGHT);
break;
}
}
}
我的XML
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.testavd.MainActivity" >
<RadioGroup
android:id="@+id/rdG"
android:layout_width="fill_parent"
android:layout_height="match_parent"
>
<RadioButton
android:id="@+id/rbRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/rbLeft"
android:layout_below="@+id/rbLeft"
android:layout_marginTop="36dp"
android:text="Right" />
<RadioButton
android:id="@+id/rbLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="17dp"
android:layout_toLeftOf="@+id/button1"
android:text="Left" />
<RadioButton
android:id="@+id/rbCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignLeft="@+id/rbRight"
android:layout_marginBottom="16dp"
android:text="Center" />
</RadioGroup>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="@+id/textOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="32dp"
android:text="Output"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
謝謝先生..所以它的XML是我的問題。 你幫了我很多..更多的權力 –