android-widget - 在 Android UI 上动态扩展小部件

标签 android-widget android

我正在尝试创建一个由 EditText 和 Button 小部件组成的简单 Android UI。但是我在设置布局属性时遇到了一些问题。用户界面应该是这样的:

▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒

左边是 EditText,右边是 Button。按钮 (ImageButton) 的宽度约为 50x50,我想将其固定。然而,TextBox 应该跨越按钮的整个可用空间,但我无法让它工作。我想让这项工作动态进行,这样我就不必为不同的屏幕尺寸或方向指定不同的布局(如果可能的话)。

这是我的第一个 Android 应用程序,所以我很感激任何有关如何最好地构建应用程序 UI 的建议。

谢谢,
b3n

最佳答案

这应该按照您的需要放置元素。

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView  

    android:layout_weight="0.5"
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:text="text"/>

    <Button 
    android:id="@+id/b1"
    android:text="test" 
    android:layout_height="50px"
    android:layout_width="50px"
/>

关于android-widget - 在 Android UI 上动态扩展小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3877332/

相关文章:

android - 如何更改 android 中下拉 View 的标题?

java - 如何更改微调项目中文本的背景颜色?

java - 小部件 Onclick 不起作用

android - 如何定位特定的 Calabash 功能文件?

android - 构建工具错误 "Please install the Android build tools version 19.1.0 or higher"

android - 动画时禁用所有触摸屏交互

Android:以编程方式将 UI 元素添加到 View

android - 我可以在 viewpager 中的内容之外向 FragmentActivity 添加 fragment 吗?

java - 两种实现回调的方式,那么他有什么区别

android - 在 NAT 后面工作 - 一种设备通信方案