android - 在android中将TextView设置到垂直LinearLayout的右侧

标签 android layout textview android-linearlayout

我尝试将 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/

相关文章:

javascript - Ionic Push Android 推送通知返回 "undefined"消息

android - TabHost 未显示在屏幕中

android - TextView 上的自动链接网页结果错误

android - 如何以编程方式为 TextView 或基于 Android 的应用程序的 TableRow 添加边距?

java - 为什么我收到 'UNIQUE constraint failed' 错误

android - 检测特定应用程序(不是我的)何时对用户可见/不可见

java - Android调试器隐藏局部变量

android - 当 Horizo​​ntalScrollView 的元素不足以使其滚动时居中

ios - 如何使用 Xcode Storyboard 保持导入图像的原始尺寸?

android - 检查字符串是否从我在 android 中的 View 中溢出?