android - 安卓用户界面的规则

标签 android android-layout android-widget

我的 Android 用户界面有问题。我的按钮没有正确对齐。即使我的按钮右对齐,但仍然无法正确对齐?

我想知道是否有任何文档可以解释如何正确布局事物以及小部件在表格行内时的行为方式?或者换句话说,层次结构如何影响事物的排列方式? 谢谢

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    style="?screenBackground">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent">
        <TableLayout android:id="@+id/TableLayout02"
            android:layout_width="match_parent" android:layout_height="match_parent"
            style="?pageBackground">
            <TableRow>
                <ImageView android:layout_height="wrap_content"
                    android:layout_width="wrap_content" android:src="@drawable/camera_icon"
                    android:id="@+id/img" android:layout_gravity="left"></ImageView>
                <Button android:id="@+id/button1" android:text="@string/button1"
                    style="?button"></Button>

            </TableRow>

        </TableLayout>
    </LinearLayout>
</ScrollView> 

最佳答案

使用 RelativeLayout 而不是 LinearLayout 可能会更好。

例如,您可以像这样对齐 ImageViewButton:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content">

    <ImageView 
        android:layout_height="60dip"
        android:layout_width="60dip" 
        android:layout_alignParentLeft="true"/>

    <Button 
        android:text="Button" 
        android:layout_alignParentRight="true" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>

</RelativeLayout>

为了了解什么是可能的,RelativeLayout 上的入门文档是 herehere .

关于android - 安卓用户界面的规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6588827/

相关文章:

android - 不幸的是,应用程序已停止 - 在 if-else 条件下显示 Toast

滚动时的Android工具栏提升

android - 在 Android 中关闭弹出窗口

android - 如何通过动态应用主题来更改 TextView 、按钮、编辑文本的角的形状?

android - appwidget appWidgetIds 的问题(小部件的真实实例和虚拟实例)

android - Firebase 在不读取快照或尝试写入(对于唯一用户名)的情况下检查值是否存在?

android - 使用停止按钮停止音乐后播放按钮不起作用

Android Studio 3 - 约束布局编辑器不工作

Android fragment onResume 与 onCreateView

android - 在线性布局中扩展显示日期选择器对话框而不是 Activity