Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.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
Java 宽度和高度匹配的问题_Java_Android_Xml_Android Layout_Android Linearlayout - Fatal编程技术网

Java 宽度和高度匹配的问题

Java 宽度和高度匹配的问题,java,android,xml,android-layout,android-linearlayout,Java,Android,Xml,Android Layout,Android Linearlayout,我正在尝试建立这个布局 但我明白了:(该位置的地图按钮将是理想的高度和宽度,但textview与高度不匹配) 我的位置是文本视图,我的目的地是编辑文本 我希望文本视图和编辑文本的宽度相同,而地图按钮保持“方形” 如何使textviews高度匹配并制作方形地图按钮 这是我的布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="ht

我正在尝试建立这个布局

但我明白了:(该位置的地图按钮将是理想的高度和宽度,但textview与高度不匹配)

我的位置是
文本视图
,我的目的地是
编辑文本

我希望
文本视图
编辑文本
的宽度相同,而地图按钮保持“方形”

如何使textviews高度匹配并制作方形地图按钮

这是我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/fragment_details"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.mycompany.controller.DetailsFragment">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/viewStatus"
        android:layout_marginTop="5dp">


        <LinearLayout
            android:id="@+id/scrollViewDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">


            <!-- LOCATION -->
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="LOCATION"
                android:textColor="@color/COLOR_BLUE"
                android:textSize="24sp"/>

            <LinearLayout
                android:id="@+id/layoutLocation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/tvLocation"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginTop="10dp"
                    android:layout_weight=".8"
                    android:background="@color/COLOR_LIGHT_GREY"
                    android:text="123 MAIN ST., CHATTANOOGA TN 37404"
                    android:textSize="24sp"/>

                <Button
                    android:id="@+id/btnMapLocation"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight=".2"
                    android:background="@color/COLOR_BLUE"
                    android:text="MAP"
                    android:textColor="@color/COLOR_WHITE"/>
            </LinearLayout>

            <!-- DESTINATION -->

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="DESTINATION"
                android:textColor="@color/COLOR_BLUE"
                android:textSize="24sp"/>

            <LinearLayout
                android:id="@+id/layoutDestination"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/editDestination"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight=".8"
                    android:ems="10"
                    android:inputType="textMultiLine"
                    android:text="407 Broad St., Anywhere ST 00000"/>


                <Button
                    android:id="@+id/btnMapDestination"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight=".2"
                    android:background="@color/COLOR_BLUE"
                    android:text="MAP"
                    android:textColor="@color/COLOR_WHITE"/>
            </LinearLayout>


        </LinearLayout>
    </ScrollView>

</RelativeLayout>

由于您使用的是
android:layout\u weight
,请设置
android:layout\u width=“0dp”


由于您使用的是
android:layout\u weight
,请设置
android:layout\u width=“0dp”


我对您的代码做了一点小小的修改,请检查

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/fragment_details"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
           >


<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:layout_marginTop="5dp">


    <LinearLayout
        android:id="@+id/scrollViewDetails"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <!-- LOCATION -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="LOCATION"

            android:textSize="24sp"/>

        <LinearLayout
            android:id="@+id/layoutLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/searchText"
                android:text="Search text here"
                android:layout_weight="0.8"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:background="#c8c8c8"
                />

            <Button
                android:id="@+id/searchButton"
                android:text="MAP"
                android:layout_weight="0.2"

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

        <!-- DESTINATION -->

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="DESTINATION"

            android:textSize="24sp"/>

        <LinearLayout
            android:id="@+id/layoutLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/searchText"
                android:text="Search text"
                android:layout_weight="0.8"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                />

            <Button
                android:id="@+id/searchButton"
                android:text="MAP"
                android:layout_weight="0.2"
                android:layout_alignParentRight="true"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                />
        </LinearLayout>

    </LinearLayout>
</ScrollView>

</RelativeLayout>

/>

我对您的代码做了一点小小的修改,请检查

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/fragment_details"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
           >


<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:layout_marginTop="5dp">


    <LinearLayout
        android:id="@+id/scrollViewDetails"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <!-- LOCATION -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="LOCATION"

            android:textSize="24sp"/>

        <LinearLayout
            android:id="@+id/layoutLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/searchText"
                android:text="Search text here"
                android:layout_weight="0.8"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:background="#c8c8c8"
                />

            <Button
                android:id="@+id/searchButton"
                android:text="MAP"
                android:layout_weight="0.2"

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

        <!-- DESTINATION -->

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="DESTINATION"

            android:textSize="24sp"/>

        <LinearLayout
            android:id="@+id/layoutLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/searchText"
                android:text="Search text"
                android:layout_weight="0.8"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                />

            <Button
                android:id="@+id/searchButton"
                android:text="MAP"
                android:layout_weight="0.2"
                android:layout_alignParentRight="true"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                />
        </LinearLayout>

    </LinearLayout>
</ScrollView>

</RelativeLayout>

/>

使用权重永远不能保证事物是方形的,关键是它们拉伸以填充与布局方向相关的特定大小(在本例中为水平)。如果希望某个对象是正方形,则需要显式设置宽度和高度,或者在绘制视图后获得测量的高度,并将宽度设置为匹配。使用权重永远不能保证对象是正方形,关键是它们会拉伸以填充与布局方向相关的特定大小(在本例中为水平)。如果希望某个对象为正方形,则需要显式设置宽度和高度,或者在绘制视图后获得测量的高度,并将宽度设置为匹配。