【问题标题】:How to obtain this xml android layout如何获取这个 xml android 布局
【发布时间】:2014-04-23 08:49:42
【问题描述】:

我见过这种布局 (http://cdn0.tnwcdn.com/wp-content/blogs.dir/1/files/2014/03/Instaedit1.jpg),我想做类似的事情,但我不知道我必须做什么才能获得这个结果。 我尝试过包含一个 imageview 和一个包含三个 imagebutton 的 gridlayout 的相对布局。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.prova.MainActivity$PlaceholderFragment" xmlns:app="http://schemas.android.com/apk/res/com.example.prova">

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/profile" />

<android.support.v7.widget.GridLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/imageView1"
    app:columnCount="3"
    app:orientation="horizontal"
    app:rowCount="1"
    app:useDefaultMargins="false" >

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_gravity="fill_horizontal"
        android:scaleType="center"
        android:src="@drawable/friend" />

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_gravity="fill_horizontal"
        android:maxHeight="100dp"
        android:src="@drawable/fotocamera" />

    <ImageButton
        android:id="@+id/imageButton3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:src="@drawable/eventi" />
</android.support.v7.widget.GridLayout>

</RelativeLayout> 

但我没有获得图像顶部的相同结果。 我试过改变重力值和宽度值,但没有。 你能帮助我吗??? (对不起我的英语不好:P 谢谢)。

【问题讨论】:

  • 你的结果是什么?可能会发布截图,因为布局相当复杂。
  • 你到底想达到什么目标?
  • 这是it.tinypic.com/r/2rf9fdf/8的结果@gridlayout中的三个图像按钮没有占据所有水平空间。

标签: android xml android-layout layout android-gridlayout


【解决方案1】:

我处理了你的代码来获得这个:http://it.tinypic.com/view.php?pic=2aj1cms&s=8#.UyhKXtT5OBM 这是一个更好的结果,但我不明白为什么图像按钮之间有空间。 我的代码是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/com.example.prova"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.prova.MainActivity$PlaceholderFragment" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="4" >

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/profile" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:orientation="vertical"
        android:weightSum="3" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:weightSum="3" >

            <ImageButton
                android:id="@+id/imageButton2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@drawable/friend" />

            <ImageButton
                android:id="@+id/imageButton3"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@drawable/fotocamera" />

            <ImageButton
                android:id="@+id/imageButton4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@drawable/eventi" />

        </LinearLayout>

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Aggiungi agli amici" />

    </LinearLayout>

</LinearLayout>

有什么想法吗??

【讨论】:

  • 您可能在某处设置了一些边距 - 在 values 文件夹/s 中查看您的主题、样式、尺寸文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多