不同的屏幕大小更改查看Android

时间:2014-09-30 09:37:16

标签: android css android-linearlayout

在我的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上运行时,图表中没有空格及其下方的详细信息。

在三星Galaxy note3上运行时。图表中有一个空格,下面有详细信息。

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

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

谢谢需要帮助。或者无论如何我可以用css解决这个问题? 金斯利 PS:发布图片我需要10个声望,因此没有附加图片。

1 个答案:

答案 0 :(得分:0)

你可以尝试一件事, 以编程方式获取屏幕大小并选择适合所有屏幕大小的屏幕大小的百分比,并将其设置为您查看。

试试这个例子

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);
相关问题