简体   繁体   English

Android GUI无法在相对布局中正确显示

[英]Android GUI not displaying properly in relative layout

I am creating gui in relative layout and reason i am using relative layout is that, i am using a fakeview in the middle of the screen to align all the other objects properly in the center of the screen. 我在相对布局中创建gui,而我使用相对布局的原因是,我在屏幕中间使用了一个fakeview来将所有其他对象正确对齐在屏幕中央。 But the output on my mobile is completely different and is completely stretch out. 但是我的手机上的输出完全不同,并且完全可以扩展。

My problem is that the black line in the middle is supposed to be just 1dp in height, still it appears as 50dp in height on my device. 我的问题是中间的黑线应该只是1dp的高度,但在我的设备上仍然显示为50dp的高度。 Also there is huge gap in the middle below exchange rate and above discount amt($). 在汇率以下和折扣amt($)上方的中间也存在巨大差距。 Such problems weren't there in the emulator. 模拟器中不存在此类问题。 the entire screen is divided into two parts, the lower part and upper part and there is gap in middle. 整个屏幕分为上下两部分,中间有缝隙。

I am using nexus 4 running stock rom 4.4.2 to test my application. 我正在使用nexus 4流动版rom 4.4.2来测试我的应用程序。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="#FFFFE0">

    <View android:id="@+id/fakeView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/carat"
        android:layout_marginTop="10dp"

        android:layout_below="@+id/cut3"

        android:layout_alignParentRight="true"
        android:layout_alignLeft="@+id/fakeView"
        android:layout_marginRight="20dp"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/price"
        android:layout_above="@+id/caratrs"
        android:layout_alignParentRight="true"
        android:layout_alignLeft="@+id/fakeView"
        android:layout_marginRight="20dp"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/list"
        android:layout_marginRight="20dp"


        android:layout_below="@+id/carat"
        android:layout_alignParentRight="true"
        android:layout_alignLeft="@+id/fakeView" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/total"
        android:layout_marginRight="20dp"

        android:layout_above="@+id/calculate"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/fakeView" />

    <Spinner
        android:drawSelectorOnTop="true"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/shape2"
        android:layout_toLeftOf="@+id/color"
        android:layout_alignLeft="@+id/cut3" />

    <Spinner
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/cut3"
        android:layout_below="@+id/shape2"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/fakeView"
        android:layout_marginLeft="20dp"
        />

    <Spinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/color"
        android:layout_above="@+id/cut3"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/fakeView"
        android:layout_marginRight="20dp" />

    <Spinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/clarity"
        android:layout_below="@+id/shape2"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/shape2"
        android:layout_marginRight="20dp"/>

    <EditText

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/discount"
        android:layout_marginRight="20dp"
        android:layout_below="@+id/list"
        android:layout_toRightOf="@+id/fakeView" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/converter"
        android:layout_marginRight="20dp"
        android:layout_below="@+id/discount"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/fakeView" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Calculate"
        android:id="@+id/calculate"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@android:color/black"
        android:layout_below="@+id/converter"
        android:layout_marginTop="20dp"
        android:layout_alignParentLeft="true"
        android:id="@+id/view"
        android:layout_above="@+id/textView5" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/discamt"
        android:layout_below="@+id/view"
        android:layout_above="@+id/price"
        android:layout_alignLeft="@+id/fakeView" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:layout_marginRight="20dp"
        android:id="@+id/caratrs"
        android:layout_above="@+id/total"
        android:layout_toRightOf="@+id/fakeView" />



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Rap Price"
        android:id="@+id/textView2"
        android:layout_above="@+id/discount"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Discount(%)"
        android:id="@+id/textView3"
        android:layout_above="@+id/converter"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Exchange Rate"
        android:id="@+id/textView4"
        android:layout_alignBottom="@+id/converter"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Discount Amt($)"
        android:id="@+id/textView5"
        android:layout_above="@+id/price"

        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="PPC($)"
        android:id="@+id/textView6"

        android:layout_above="@+id/caratrs"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/ppcrs"
        android:id="@+id/textView7"
        android:layout_above="@+id/total"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/Rs"
        android:id="@+id/textView8"
        android:layout_above="@+id/calculate"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Carat :"
        android:id="@+id/textView9"
        android:layout_alignBottom="@+id/carat"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"/>

</RelativeLayout>

这是屏幕截图

In your black view remove 在您的黑视图中删除

 android:layout_above="@+id/textView5"

You'll end up with the following: 您将得到以下结果:

<View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@android:color/black"
    android:layout_below="@+id/converter"
    android:layout_marginTop="20dp"
    android:layout_alignParentLeft="true"
    android:id="@+id/view" />

You're already anchoring the view to converter 您已经将视图锚定到转换器

So you don't need the extra anchor. 因此,您不需要额外的锚点。

我强烈建议您不要使用假视图,从屏幕快照中,最好使用linearlayout在屏幕上保留空白,并且每个空白都可以使用相对布局,这样,这种布局在所有设备上都可以很好地显示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM