簡體   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