我尝试将 TextView 添加到垂直的 LinearLayout 并将 TextView 对齐到布局的右侧:
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));
但是 TextView 仍然与布局的左侧对齐
最佳答案
尝试将 LinearLayout 设置为 MATCH_PARENT 宽度。
关于android - 在android中将TextView设置到垂直LinearLayout的右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7945254/