FrameLayout 的问题
我正在以编程方式将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个 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.