Android 谷歌风格版本信息对话框

Android 谷歌风格版本信息对话框,android,android-layout,android-view,android-xml,Android,Android Layout,Android View,Android Xml,我希望模仿大多数(如果不是全部)谷歌应用中的版本信息对话框。这些对话框通常位于“帮助和反馈”>“选项菜单”>“版本信息”中。例如,这是照片应用程序中的对话框: 我无法将标题和版本号文本相对于图标居中,同时将版权文本与标题和版本的左边缘对齐。我知道我可以通过这样做将两个TextView元素居中放置: <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" androi

我希望模仿大多数(如果不是全部)谷歌应用中的版本信息对话框。这些对话框通常位于“帮助和反馈”>“选项菜单”>“版本信息”中。例如,这是照片应用程序中的对话框:

我无法将标题和版本号文本相对于图标居中,同时将版权文本与标题和版本的左边缘对齐。我知道我可以通过这样做将两个
TextView
元素居中放置:

<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"
    android:padding="@dimen/padding">

    <ImageView android:id="@+id/icon"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding" android:src="@mipmap/ic_launcher"/>

    <LinearLayout android:id="@+id/title_layout" android:orientation="vertical"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_toEndOf="@id/icon" android:layout_centerVertical="true">

        <TextView android:id="@+id/title"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="@dimen/title"/>

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

    </LinearLayout>
</FrameLayout>
<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TableRow>
        <ImageView android:id="@+id/icon"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:src="@mipmap/ic_launcher"/>

        <LinearLayout android:id="@+id/title_layout" 
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:paddingTop="16dp" 
            android:layout_height="wrap_content" >

            <TextView android:id="@+id/title"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:textSize="16sp"
                android:text="first line"/>

            <TextView android:id="@+id/another"
                android:layout_width="wrap_content"     
                android:layout_height="wrap_content"
                android:text="second line"/>

        </LinearLayout>
    </TableRow>
    <TableRow>
        <Space />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="thirdline"/>
    </TableRow>

</TableLayout>

但是,我如何添加版权
TextView
而不弄乱中心呢?我也尝试过使用
坐标布局
,但似乎无法使这两个
文本视图
元素在保持居中的同时与图标右侧对齐。我还想将
列表视图
(或
回收视图
)添加到版权文本下方的对话框中,但在我弄明白这一点后,这应该不会太困难


我能想到的唯一一件事是将整个内容包装到另一个布局中,在该布局中添加一个
TextView
,并给它一个与
ImageView
宽度相等的左边距(包括其边距)。但是我觉得我应该能够做到这一点,而不必添加Java代码,或者硬编码一个等于
ImageView

宽度的维度。我建议您使用TableLayout,因此代码如下:

<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"
    android:padding="@dimen/padding">

    <ImageView android:id="@+id/icon"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding" android:src="@mipmap/ic_launcher"/>

    <LinearLayout android:id="@+id/title_layout" android:orientation="vertical"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_toEndOf="@id/icon" android:layout_centerVertical="true">

        <TextView android:id="@+id/title"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="@dimen/title"/>

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

    </LinearLayout>
</FrameLayout>
<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TableRow>
        <ImageView android:id="@+id/icon"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:src="@mipmap/ic_launcher"/>

        <LinearLayout android:id="@+id/title_layout" 
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:paddingTop="16dp" 
            android:layout_height="wrap_content" >

            <TextView android:id="@+id/title"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:textSize="16sp"
                android:text="first line"/>

            <TextView android:id="@+id/another"
                android:layout_width="wrap_content"     
                android:layout_height="wrap_content"
                android:text="second line"/>

        </LinearLayout>
    </TableRow>
    <TableRow>
        <Space />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="thirdline"/>
    </TableRow>

</TableLayout>

这就是我手机上的样子

我建议您使用TableLayout,因此代码如下:

<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"
    android:padding="@dimen/padding">

    <ImageView android:id="@+id/icon"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding" android:src="@mipmap/ic_launcher"/>

    <LinearLayout android:id="@+id/title_layout" android:orientation="vertical"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_toEndOf="@id/icon" android:layout_centerVertical="true">

        <TextView android:id="@+id/title"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="@dimen/title"/>

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

    </LinearLayout>
</FrameLayout>
<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TableRow>
        <ImageView android:id="@+id/icon"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:src="@mipmap/ic_launcher"/>

        <LinearLayout android:id="@+id/title_layout" 
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:paddingTop="16dp" 
            android:layout_height="wrap_content" >

            <TextView android:id="@+id/title"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:textSize="16sp"
                android:text="first line"/>

            <TextView android:id="@+id/another"
                android:layout_width="wrap_content"     
                android:layout_height="wrap_content"
                android:text="second line"/>

        </LinearLayout>
    </TableRow>
    <TableRow>
        <Space />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="thirdline"/>
    </TableRow>

</TableLayout>

这就是我手机上的样子

使用RelativeLayout并将文本视图设置为与ImageView右侧对齐(android:layout_-toRightOf=“@id/icon”)

使用RelativeLayout并将文本视图设置为与ImageView右侧对齐(android:layout_-toRightOf=“@id/icon”)

我想这是您想要的(我通过
RelativeLayout
来实现这一点):



我想这就是你想要的(我是通过
RelativeLayout
来实现的):



啊,这很好用!老实说,我已经忘记了
表格布局
。啊,这很好用!老实说,我已经忘记了
表格布局
。这也很有效,我没有想到在标题文本布局中嵌套另一个
RelativeLayout
。我曾尝试将
android:layou centerVertical
属性应用于外部布局,但我不明白为什么它实际上不会将
TextView
元素置于内部。我之所以选择@бббббббббббббббббббббб的答案,唯一原因是。我曾尝试将
android:layou centerVertical
属性应用于外部布局,但我不明白为什么它实际上不会将
TextView
元素置于内部。我同意@khааааабааааааааааа。