在Android中水平对齐5个文本视图
我需要你的帮助来解决这个问题: 我有一个水平方向的线性布局。在这个布局中,我有5个文本视图,其可见性为:消失。在这个布局上面,我有一个单选组,有5个单选按钮水平对齐 当我选中一个单选按钮时,相应的文本视图会改变他的可视性。我想在每个单选按钮下面显示一个文本视图。实际上他们都处在同一个位置在Android中水平对齐5个文本视图,android,textview,radio-button,android-linearlayout,Android,Textview,Radio Button,Android Linearlayout,我需要你的帮助来解决这个问题: 我有一个水平方向的线性布局。在这个布局中,我有5个文本视图,其可见性为:消失。在这个布局上面,我有一个单选组,有5个单选按钮水平对齐 当我选中一个单选按钮时,相应的文本视图会改变他的可视性。我想在每个单选按钮下面显示一个文本视图。实际上他们都处在同一个位置 <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orie
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView />
<TextView />
<TextView />
<TextView />
<TextView />
</LinearLayout>
如何做到这一点?使用
可见性:不可见
而不是消失
,因为使用消失
时,他们不使用任何屏幕,因此当所选屏幕出现时,其余屏幕实际上不存在,它将出现在第一个位置
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView />
<TextView />
<TextView />
<TextView />
<TextView />
</LinearLayout>
希望这有帮助。将LinearLayout Weighthsum设置为1.0。使每个textview权重为0.2,可见性为不可见可见性消失的视图不占用任何空间
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.yourRadioGroup);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// checkedId is the RadioButton selected
// set visibility in visible according to Id by using if condition Or switch
}
});
我使第二个文本视图可见。但文本为“1”的textview将占据文本为“2”的textview之前的空间
显示它现在的外观以及您希望它的外观(显示一些图像)
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.yourRadioGroup);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
/*hide all*/
TextView tv;
if(checkedID==R.id.radioButton1)
tv=(RadioButton)findViewById(R.id.text1);
elseif(checkedID==R.id.radioButton2)
tv=(RadioButton)findViewById(R.id.text2);
/* Similarly other else conditions*/
tv.setVisibility(View.VISIBLE);
}
});