Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为android制作此布局?_Android_Android Linearlayout - Fatal编程技术网

如何为android制作此布局?

如何为android制作此布局?,android,android-linearlayout,Android,Android Linearlayout,[已解决]我想做一个非常具体的布局。感觉它应该很容易创建,但我似乎无法用手指去缠绕它。所以我想创建一个布局,看起来像下图。我怎么会得到这个?我只是得到文本和两个图像,然后让按钮可见。也在下面发布了我的布局 提前谢谢//eXpliCo 编辑:我现在有了一个解决方案。我不知道这是否是最好的,但它对我很有效。但是我还不能回答我自己的代码,所以我将在这里发布我的解决方案 <LinearLayout xmlns:android="http://schemas.android.com/apk/r

[已解决]我想做一个非常具体的布局。感觉它应该很容易创建,但我似乎无法用手指去缠绕它。所以我想创建一个布局,看起来像下图。我怎么会得到这个?我只是得到文本和两个图像,然后让按钮可见。也在下面发布了我的布局

提前谢谢//eXpliCo


编辑:我现在有了一个解决方案。我不知道这是否是最好的,但它对我很有效。但是我还不能回答我自己的代码,所以我将在这里发布我的解决方案

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Test123 312 123 312"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="100" >

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Test" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Test" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="test" />

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="test" />

    </LinearLayout>

</LinearLayout>

在第二个
线性布局中,将
方向设置为
水平方向

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView 
        android:text="Some Text here"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/SomeText"
        android:gravity="center"
        android:textSize="20sp" />

    <LinearLayout
        android:id="@+id/image_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/SomeText"
        android:orientation="horizontal" >


        <ImageView
            android:id="@+id/left_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/right_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"
            android:layout_weight="1" />



    </LinearLayout>

    <LinearLayout
        android:id="@+id/button_layout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/image_layout"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/vote_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1"
            android:layout_weight="1"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp" />

        <Button
            android:id="@+id/vote_right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 2"
            android:layout_weight="1"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/button_layout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button_layout1"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/vote_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 3"
            android:layout_weight="1"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp" />

        <Button
            android:id="@+id/vote_right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 4"
            android:layout_weight="1"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp" />

    </LinearLayout>
</RelativeLayout>

听起来这适用于较小的图像,但不适用于较大的图像。如果是这种情况,则在每个子项中使用
layou weight
LinearLayout
,以便每个子项占用一定的空间。这将有助于
布局
在不同的屏幕大小和分辨率下看起来相似

比如说

<TextView 
    android:text="Some Text here"
    android:layout_weight="1"
    ...
LinearLayout
    android:id="@+id/image_layout"
    android:layout_weight="3"
    ...
<LinearLayout
    android:id="@+id/button_layout1"
    android:layout_weight="2"
    ...
<LinearLayout
    android:id="@+id/button_layout2"
    android:layout_weight="2"
    ...

Hmm似乎不起作用。你是什么意思?带有图像或第一组按钮的按钮?方向默认为水平,无需设置。包装图像视图的按钮将使两个图像排成一行。我认为这是你的问题,因为你没有详细说明你发布的代码到底出了什么问题。如果您的意思是在一行中的按钮之间放置分隔符,您可以使用
边距
marginLeft
marginRight
属性。问题是图像布局覆盖了两个底部布局(一次使用按钮)。两个底部布局的高度为0,它们隐藏在底部的gui下方。我需要两个底部布局来获得按钮的高度并将图像布局向上推:)很难解释:/:(这取决于您的图像大小。它适用于较小的图像,但您是说您的图像将按钮布局从屏幕上推下。您可能必须根据图像的动态程度强制执行固定的高度和/或纵横比。此代码的当前结果是什么?我认为您应该尝试使用
Relative布局
相反,如果子布局起作用,请按原样使用它们,并将图像一设置为
android:Layout_over=“+@id/vote_Layout”
<TextView 
    android:text="Some Text here"
    android:layout_weight="1"
    ...
LinearLayout
    android:id="@+id/image_layout"
    android:layout_weight="3"
    ...
<LinearLayout
    android:id="@+id/button_layout1"
    android:layout_weight="2"
    ...
<LinearLayout
    android:id="@+id/button_layout2"
    android:layout_weight="2"
    ...