Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android将两个按钮对齐在同一行上_Java_Android_Android Layout_Dynamically Generated - Fatal编程技术网

Java Android将两个按钮对齐在同一行上

Java Android将两个按钮对齐在同一行上,java,android,android-layout,dynamically-generated,Java,Android,Android Layout,Dynamically Generated,我需要对齐同一行中的按钮、和文本视图,按钮对齐右侧,文本视图也对齐右侧, 我尝试了很多方法,但先对齐文本视图,然后对齐按钮, 如何解决这个问题请任何人帮助并以编程方式解决我的问题, 在布局xml设计方面取得了一致的成功,但我在编程方面需要它。类似的东西应该可以工作。您应根据需要对此进行修改(即设置适当的文本大小、宽度、高度等) 将两个视图放置在布局内,并将方向设置为“水平” android:layout\u width=“fill\u parent” android:layout\u heig

我需要对齐同一行中的
按钮、
文本视图
,按钮对齐右侧,文本视图也对齐右侧,
我尝试了很多方法,但先对齐文本视图,然后对齐按钮, 如何解决这个问题请任何人帮助并以编程方式解决我的问题,
在布局xml设计方面取得了一致的成功,但我在编程方面需要它。

类似的东西应该可以工作。您应根据需要对此进行修改(即设置适当的文本大小、宽度、高度等)


将两个视图放置在布局内,并将方向设置为“水平”


android:layout\u width=“fill\u parent”
android:layout\u height=“fill\u parent”
android:orientation=“horizontal”>
线性布局也可以相互嵌套


如果您想实现更多的视图行,那么您可以定义一个垂直布局(main.xml在首次创建时默认为您定义一个),并在该垂直线性布局中插入多少个水平线性布局(如我上面写的布局)。

获取线性布局(设置水平方向)和在ot.RelativeLayout上添加视图可能会解决您的问题。您应该使用布局参数以编程方式设置方向。使用
RelativeLayout
与此问题无关。
TextView tv = new TextView(this);  
tv.setText("Text");  

Button bt = new Button(this);  
bt.setText("Button");  

LinearLayout ll = new LinearLayout(this);  
ll.setOrientation(LinearLayout.HORIZONTAL);  
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  
ll.addView(tv);  
ll.addView(bt);
setContentView(ll);  
<LinearLayout>

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>