简体   繁体   English

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

[英]Different Screen Sizes Changes View Android

In my Android code, I create a graph. 在我的Android代码中,我创建了一个图形。 But in two different devices, the "match_parent" doesnt act as supposed to. 但是在两个不同的设备中,“ match_parent”并不像预期的那样起作用。

This is part of the company_header.xml 这是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>

When it is run on Google Nexus 10. there is no space within the graph and the details below it. 当它在Google Nexus 10上运行时,该图及其下方的详细信息内没有空间。

When it is run on Samsung Galaxy note3. 在Samsung Galaxy note3上运行时。 there is a space within the graph and the details below it. 在图表及其下方的详细信息中有一个空格。

When I change android:layout_height = match_parent, the graph disappears for both screen devices. 当我更改android:layout_height = match_parent时,两个屏幕设备的图形均消失。 I thought this should solve the problem since in my Android Manifest.xml i have already used the for all screen sizes. 我认为这应该可以解决问题,因为在我的Android Manifest.xml中,我已经将s用于所有屏幕尺寸。

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

Thanks need help. 谢谢需要帮助。 or is there anyway i can solve this using css? 还是无论如何我可以使用CSS解决此问题? Kingsley PS: I need 10 reputation to post images hence why no images attached. 金斯利(Kingsley)PS:我需要10名声誉才能发布图像,因此为什么不附加图像。

you can try one more thing, take screen size programmatically and select % of of screen size that fit on all screen size, and set it to you view. 您可以尝试再做一件事,以编程方式获取屏幕尺寸,然后选择适合所有屏幕尺寸的屏幕尺寸百分比,然后将其设置为您要查看的尺寸。

try this example 试试这个例子

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