Android:布局与文本相同的高度

时间:2015-05-21 11:32:27

标签: android

我正撞在墙上,因为我不明白这一点!

我需要蓝色部分布局与所包含的红色文本的高度相同。

这就是我得到的:

enter image description here

这就是我想要的:

enter image description here

这是我的XML:

    <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

        <LinearLayout
            android:id="@+id/camera_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/single_margin"
            android:background="@color/post_icons_background"
            android:orientation="vertical"
            android:paddingBottom="@dimen/single_margin"
            android:paddingLeft="@dimen/double_margin"
            android:paddingRight="@dimen/double_margin"
            android:paddingTop="@dimen/single_margin">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_camera" />

        </LinearLayout>

        <LinearLayout
            android:background="@color/primary_brand_color"
            android:id="@+id/separator_continer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:padding="0dp"
            android:weightSum="1">

            <View
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_weight="0.4"
                android:background="@color/secondary_brand_color" />

            <TextView
                style="?android:textAppearanceSmall"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="0dp"
                android:layout_weight="0.2"
                android:background="@color/accent_color"
                android:gravity="center"
                android:includeFontPadding="false"
                android:padding="0dp"
                android:text="or"
                android:textColor="@color/secondary_brand_color" />


            <View
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_weight="0.4"
                android:background="@color/secondary_brand_color" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/gallery_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/post_icons_background"
            android:orientation="vertical"
            android:paddingBottom="@dimen/single_margin"
            android:paddingLeft="@dimen/double_margin"
            android:paddingRight="@dimen/double_margin"
            android:paddingTop="@dimen/single_margin">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_gallery" />

        </LinearLayout>
    </LinearLayout>

感谢!!!!

6 个答案:

答案 0 :(得分:1)

看起来没有一个答案能够起作用,所以这就是我的问题。

string claims

我只复制了需要更改的部分,当然你不必删除内部视图。您只需要更改我更改的属性。

这样,外部<div class="bodyWrap"> <div class="header"> <h1>TITLE</h1> </div> <div class="slideshowWrapper"> <div class="slideshow"> <div class="slide"> <img src="https://picture.jpg"> </div> <div class="slide"> <img src="https://picture.jpg"> </div> <div class="prevControl"></div> <div class="nextControl"></div> <div class="slideshow"> <div class="slide"> <img src="https://picture.jpg"> </div> <div class="slide"> <img src="https://picture.jpg"> </div> <div class="prevControl"></div> <div class="nextControl"></div> <div class="slideshow"> <div class="slide"> <img src="https://picture.jpg"> </div> <div class="slide"> <img src="https://picture.jpg"> </div> <div class="prevControl"></div> <div class="nextControl"></div> <div class="slideshow"> <div class="slide"> <img src="https://picture.jpg"> </div> <div class="slide"> <img src="https://picture.jpg"> </div> <div class="prevControl"></div> <div class="nextControl"></div> </div> </div> </div> </div> <a href="#" onClick="shotit(event)">take picture</a> <script src="jquery-2.1.1.min.js"></script> <script src="html2canvas.js"></script> <script> var shotit = function(e) { e.preventDefault(); html2canvas($('.bodyWrap'), { onrendered: function(canvas) { document.body.appendChild(canvas); }, logging:true }); }; </script> 首先计算中心视图的维度,该维度没有<LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" <!-- change here if you want the layout to cover the full screen --> android:orientation="vertical"> <LinearLayout android:id="@+id/camera_container" android:layout_width="wrap_content" android:layout_height="0dp" <!-- change here --> android:layout_weight="0.5"> <!-- change here --> </LinearLayout> <LinearLayout android:id="@+id/separator_continer" android:layout_width="match_parent" android:layout_height="wrap_content"> </LinearLayout> <LinearLayout android:id="@+id/gallery_container" android:layout_width="wrap_content" android:layout_height="0dp" <!-- change here --> android:layout_weight="0.5"> <!-- change here --> </LinearLayout> </LinearLayout> 属性,并将其放下;然后,余下的空格在LinearLayoutlayout_weight之间平均分配。

答案 1 :(得分:0)

你的父亲,即第一个线性垂直布局android:layout_width =“match_parent”而不是wrap_content

答案 2 :(得分:0)

像这样更改你的布局

    <LinearLayout
        android:id="@+id/camera_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/single_margin"
        android:background="@color/post_icons_background"
        android:orientation="vertical"
        android:paddingBottom="@dimen/single_margin"
        android:paddingLeft="@dimen/double_margin"
        android:paddingRight="@dimen/double_margin"
        android:paddingTop="@dimen/single_margin">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/ic_camera" />

    </LinearLayout>

    <LinearLayout
        android:background="@color/primary_brand_color"
        android:id="@+id/separator_continer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:orientation="horizontal"
        android:padding="0dp"
        android:weightSum="1">

        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_weight="0.4"
            android:background="@color/secondary_brand_color" />

        <TextView
            style="?android:textAppearanceSmall"
            android:layout_width="0dp"
            android:layout_height="matchparent"
            android:layout_margin="0dp"
            android:layout_weight="0.2"
            android:background="@color/accent_color"
            android:gravity="center"
            android:includeFontPadding="false"
            android:padding="0dp"
            android:text="or"
            android:textColor="@color/secondary_brand_color" />


        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_weight="0.4"
            android:background="@color/secondary_brand_color" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/gallery_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/post_icons_background"
        android:orientation="vertical"
        android:paddingBottom="@dimen/single_margin"
        android:paddingLeft="@dimen/double_margin"
        android:paddingRight="@dimen/double_margin"
        android:paddingTop="@dimen/single_margin">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/ic_gallery" />

    </LinearLayout>
</LinearLayout>

答案 3 :(得分:0)

使用此布局。

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


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#ff0000">

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00ff00">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="OR" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#ff0000">

    </LinearLayout>

</LinearLayout>

答案 4 :(得分:0)

你可以使用,

android:layout_marginTop="Xdp"
android:layout_marginBottom="Xdp"

为您的textview。

答案 5 :(得分:0)

试试这个

选项1:

android:minHeight="50dp"

在您的中心textView

选项2:

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

    <LinearLayout
        android:id="@+id/camera_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:layout_marginTop="10dp"
        android:orientation="vertical"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="10dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/back" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/separator_continer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:layout_weight="0.8"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:padding="0dp"
        android:weightSum="1">

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.4"
/>

        <TextView
            style="?android:textAppearanceSmall"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="0dp"
            android:layout_weight="0.2"
            android:gravity="center"
            android:includeFontPadding="false"
            android:text="or"
/>


        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.4"
/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/gallery_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:layout_weight="0.1"
        android:paddingRight="20dp"
        android:paddingTop="10dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/back" />

    </LinearLayout>
</LinearLayout>

添加背景资源后请检查