简体   繁体   中英

Different Screen Sizes Changes View Android

In my Android code, I create a graph. But in two different devices, the "match_parent" doesnt act as supposed to.

This is part of the 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.

When it is run on 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. I thought this should solve the problem since in my Android Manifest.xml i have already used the for all screen sizes.

          *<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? Kingsley PS: I need 10 reputation to post images hence why no images attached.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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