在android中将TextView设置为垂直LinearLayout的右侧
我尝试将 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));
但 textview 保持与布局左侧对齐
I tried to add a TextView to a vertical LinearLayout and align the text view to right of layout:
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));
But the textview remains aligned to the left of layout
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 LinearLayout 设置为 MATCH_PARENT 宽度。
Try setting up your LinearLayout to MATCH_PARENT width.