FrameLayout 的问题

发布于 2024-12-05 15:26:46 字数 831 浏览 3 评论 0原文

我正在以编程方式将 3 个文本视图添加到具有相机视图的框架布局中。

三个文本视图写在同一位置,但我想将每个文本视图底部放在另一个文本视图底部(使用框架布局)

我不知道该怎么做,我找不到任何有关以编程方式使用框架布局执行此操作的示例或信息,而且我没有找到使用 setlayoutparams 执行此操作的方法,因为该方法没有 x/y 参数或类似的参数。

这是代码:

public void onCreate(Bundle savedInstanceState) 
{
       super.onCreate(savedInstanceState);
       cv = new CustomCameraView(this.getApplicationContext());
       FrameLayout rl = new FrameLayout(this.getApplicationContext());
       setContentView(rl);
       rl.addView(cv);

       tv1=new TextView(getApplicationContext());
       tv2=new TextView(getApplicationContext());
       tv3=new TextView(getApplicationContext());

       rl.addView(tv1);
       rl.addView(tv2);
       rl.addView(tv3);

       tv1.setText("Test1");
       tv2.setText("Test2");
       tv3.setText("Test3");
}

i'm adding programatically 3 textviews into a framelayout that haves a camera view.

The three textviews are writting in the same position, but i want to put each textview bottom to another (using framelayout)

I dont know how to do it, i can't find any examples or info about doing this with framelayout programatically, and also i didnt find the way to do it with setlayoutparams, because that method doesn't have x/y parameters or something like that.

here is the code:

public void onCreate(Bundle savedInstanceState) 
{
       super.onCreate(savedInstanceState);
       cv = new CustomCameraView(this.getApplicationContext());
       FrameLayout rl = new FrameLayout(this.getApplicationContext());
       setContentView(rl);
       rl.addView(cv);

       tv1=new TextView(getApplicationContext());
       tv2=new TextView(getApplicationContext());
       tv3=new TextView(getApplicationContext());

       rl.addView(tv1);
       rl.addView(tv2);
       rl.addView(tv3);

       tv1.setText("Test1");
       tv2.setText("Test2");
       tv3.setText("Test3");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灵芸 2024-12-12 15:26:46

创建一个 LinearLayout,将 textView 添加到此 LinearLayout 中,然后将此 LinearLayout 添加到您的 FrameLayout 中。使用 LinearLayout 垂直方向。

使用 LinearLayout.setOrientation(LinearLayout.VERTICAL) 方法将方向设置为垂直。

Make a linearLayout, add the textViews to this LinearLayout , and add this linearLayout to your FrameLayout. Use the orientation of LinearLayout vertical.

use LinearLayout.setOrientation(LinearLayout.VERTICAL), method for setting orientation to vertical.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文