【发布时间】:2011-12-18 05:13:23
【问题描述】:
我尝试将 TextView 添加到垂直 LinearLayout 并将文本视图与布局右侧对齐:
LinearLayout temprLayout=new LinearLayout(this);
temprLayout.setOrientation(LinearLayout.VERTICAL);
theTemprature = new TextView(this);
theTemprature.setVisibility(View.VISIBLE);
theTemprature.setTextSize(21);
theTemprature.setTextColor(0xffffCC33);
theUVText = new TextView(this);
theUVText.setVisibility(View.VISIBLE);
theUVText.setTextSize(21);
theUVText.setTextColor(0xfff5b800);
theUVText.setBackgroundColor(0xff423234);
theUVText.setGravity(Gravity.RIGHT | Gravity.TOP);
theUVText.setLayoutParams(new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.RIGHT));
temprLayout.addView(theTemprature, new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.RIGHT));
temprLayout.addView(theUVText, new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.RIGHT));
但文本视图仍然与布局的左侧对齐
【问题讨论】:
标签: android layout textview android-linearlayout