English 中文(简体)
同一线上的机器人对齐两个按钮
原标题:Android align two buttons on same line

I need to align button,and textview in on same line,button aligned right side and textview also aligned right side,
I tried lot of methods but aligned first textview then aligned button, how to solve this problem please any one help and solve my problem in programatically, aligned success in layout xml design but I need it programatically.

问题回答

将两种观点都置于您的布局中, 并设定方向为“ 横向 ” 。

<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>

线性布局也可以相互嵌入!

如果您想要执行更多的视图行, 那么您可以只定义垂直布局( 主. xml 默认会定义您最初创建时的垂直布局), 而在垂直线性布局中, 只需插入您想要的多少水平线性布局( 如我在上面写的 ) 。

类似这样的东西应该有效。 您应该修改它以适合您的需要( 即设置适当的文本大小、 宽度、 高度等 ) 。

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);  




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签