簡體   English   中英

Android布局已關閉。 需要固定位置

[英]Android layout is off. need to fix position

我希望右側的布局與其中帶有“ 20”的文本框相匹配的左側的布局。 左側的位置是我想要的位置,但右側的位置將無法正確定位。 我還想在20號上方的右上角有一個小旋轉器

在此處輸入圖片說明

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

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:gravity="center" >

    <TextView
        android:id="@+id/history1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="98dp"
        android:text="This is where life histroy goes" />

    <EditText
        android:id="@+id/playerLifeOne"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="49dp"
        android:gravity="center"
        android:inputType="number"
        android:minWidth="120dp"
        android:text="20"
        android:textSize="40dp" />

</RelativeLayout>

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >

   <Button
       android:id="@+id/badd1"
       android:layout_width="78dp"
       android:layout_height="wrap_content"
       android:text="+1" />

        <Button
            android:id="@+id/badd5"
           android:layout_width="78dp"
            android:layout_height="wrap_content"
            android:text="+5" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/bsub1"
            android:layout_width="78dp"
            android:layout_height="wrap_content"
            android:text="-1" />

        <Button
            android:id="@+id/bsub5"
            android:layout_width="78dp"
            android:layout_height="wrap_content"
            android:text="-5" />
    </LinearLayout>
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@android:color/black" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="2"
    android:gravity="center" >

    <EditText
        android:id="@+id/playerLifeTwo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="0dp"
        android:gravity="center"
        android:inputType="number"
        android:minWidth="120dp"
        android:text="20"
        android:textSize="40dp" >

        <requestFocus />
    </EditText>

 </LinearLayout>

 <LinearLayout
    android:layout_width="156dp"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b2add1"
            android:layout_width="78dp"
            android:layout_height="wrap_content"
            android:text="+1" />

        <Button
            android:id="@+id/b2add5"
            android:layout_width="78dp"
            android:layout_height="wrap_content"
            android:text="+5" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b2sub1"
           android:layout_width="78dp"
            android:layout_height="wrap_content"
            android:text="-1" />

        <Button
            android:id="@+id/b2sub5"
            android:layout_width="78dp"
            android:layout_height="wrap_content"
            android:text="-5" />

    </LinearLayout>
 </LinearLayout>
 </LinearLayout>

</LinearLayout>

這對我有用。 更改#2以匹配#1:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2" >

        <EditText
            android:id="@+id/playerLifeTwo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="49dp"
            android:gravity="center"
            android:inputType="number"
            android:minWidth="120dp"
            android:text="20"
            android:textSize="40dp" />
    </RelativeLayout>

如果您要查找下面的圖像,可以使用(修改后的)布局。

在此處輸入圖片說明

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

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:gravity="center" >

            <TextView
                android:id="@+id/history1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="98dp"
                android:text="This is where life histroy goes" />

            <EditText
                android:id="@+id/playerLifeOne"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="49dp"
                android:gravity="center"
                android:inputType="number"
                android:minWidth="120dp"
                android:text="20"
                android:textSize="40dp" />
        </RelativeLayout>

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/badd1"
                    android:layout_width="78dp"
                    android:layout_height="wrap_content"
                    android:text="+1" />

                <Button
                    android:id="@+id/badd5"
                    android:layout_width="78dp"
                    android:layout_height="wrap_content"
                    android:text="+5" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/bsub1"
                    android:layout_width="78dp"
                    android:layout_height="wrap_content"
                    android:text="-1" />

                <Button
                    android:id="@+id/bsub5"
                    android:layout_width="78dp"
                    android:layout_height="wrap_content"
                    android:text="-5" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="@android:color/black" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:gravity="top" >

            <EditText
                android:id="@+id/playerLifeTwo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="49dp"
                android:gravity="center"
                android:inputType="number"
                android:minWidth="120dp"
                android:text="20"
                android:textSize="40dp" >
                <requestFocus />
                </EditText>
                <Spinner 
                    android:id="@+id/spinner"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentRight="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
        </RelativeLayout>

        <LinearLayout
            android:layout_width="156dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/b2add1"
                    android:layout_width="78dp"
                    android:layout_height="wrap_content"
                    android:text="+1" />

                <Button
                    android:id="@+id/b2add5"
                    android:layout_width="78dp"
                    android:layout_height="wrap_content"
                    android:text="+5" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/b2sub1"
                    android:layout_width="78dp"
                    android:layout_height="wrap_content"
                    android:text="-1" />

                <Button
                    android:id="@+id/b2sub5"
                    android:layout_width="78dp"
                    android:layout_height="wrap_content"
                    android:text="-5" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM