繁体   English   中英

不同的屏幕尺寸更改查看Android

[英]Different Screen Sizes Changes View Android

在我的Android代码中,我创建了一个图形。 但是在两个不同的设备中,“ match_parent”并不像预期的那样起作用。

这是company_header.xml的一部分

<RelativeLayout
    android:id="@+id/rlForScreenShot"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true" >

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

        *<com.kite.chart.chart.ChartView
            android:id="@+id/cvChart"
            android:layout_width="match_parent"
            android:layout_height="200dp" />*

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

            <TextView
                android:id="@+id/tvCompanyName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Loading" />

            <TextView
                android:id="@+id/tvCompanyPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Loading" />

            <TextView
                android:id="@+id/tvCompanyChange"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Loading" />
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

当它在Google Nexus 10上运行时,该图及其下方的详细信息内没有空间。

在Samsung Galaxy note3上运行时。 在图表及其下方的详细信息中有一个空格。

当我更改android:layout_height = match_parent时,两个屏幕设备的图形均消失。 我认为这应该可以解决问题,因为在我的Android Manifest.xml中,我已经将s用于所有屏幕尺寸。

          *<com.kite.chart.chart.ChartView
            android:id="@+id/cvChart"
            android:layout_width="match_parent"
            **android:layout_height="match_parent**" />*

谢谢需要帮助。 还是无论如何我可以使用CSS解决此问题? 金斯利(Kingsley)PS:我需要10名声誉才能发布图像,因此为什么不附加图像。

您可以尝试再做一件事,以编程方式获取屏幕尺寸,然后选择适合所有屏幕尺寸的屏幕尺寸百分比,然后将其设置为您要查看的尺寸。

试试这个例子

DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int height = displaymetrics.heightPixels;
        int width = displaymetrics.widthPixels;
        int heightPercent=0;
        LayoutParams lay;
        if (height > width){
            heightPercent=(35*height)/100;
            lay=new LayoutParams(LayoutParams.MATCH_PARENT, heightPercent);
        }else {
            heightPercent=(25*width)/100;
            lay=new LayoutParams(LayoutParams.MATCH_PARENT, heightPercent);
        }

        view.setLayoutParams(lay);

暂无
暂无

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

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