hanleyhansen
hanleyhansen

Reputation: 6452

Android Screen Density Layout Issues

My app is supposed to look like this:

enter image description here

But for some reason on the Galaxy S4 it looks like this:

enter image description here

The pager indicators are a lot smaller and I can't see the next hexagon. This is my channel pager: https://gist.github.com/hanleyhansen/e0a5aae4ad1548316b91

It seems to happen on screen with higher resolutions.

This is how I'm drawing the hexagons: https://gist.github.com/hanleyhansen/0b6f032daaf74d012925

And this is my fragment_channel.xml: https://gist.github.com/hanleyhansen/70b865b0e982ee7e0536

How I'm drawing the indicators: https://gist.github.com/hanleyhansen/8037f74304a32565228d

Upvotes: 0

Views: 188

Answers (2)

petey
petey

Reputation: 17140

For the dots, you are drawing using pixel. so these circles on a xhdpi screen will be visually smaller than on an mdpi screen (where pixels are bigger).

In order to get similiar sizing (using more pixels on on higher dpi devices) I suggest changing PageControl as follows.

public class PageControl extends LinearLayout {

    int page = 0;
    int count = 0;
    int spacer = 8;
    private Boolean centered = true;

    int r;
    final int rDP = 8;  // DP value (needs conversion to dp placed into r)
    private final Paint mNormal = new Paint(Paint.ANTI_ALIAS_FLAG);
    private final Paint mSelected = new Paint(Paint.ANTI_ALIAS_FLAG);

    public PageControl(Context context) {
            super(context);
            r = dpToPx(context, rDP);
            setWillNotDraw(false);
    }

    public PageControl(Context context, AttributeSet attrs) {
            super(context, attrs);
            r = dpToPx(context, rDP);
            setWillNotDraw(false);
            setCentered(true);
    }

public int dpToPx(int dp) {
        float density = getResources().getDisplayMetrics().density
        return (int) (dp * density + 0.5f);
}

Upvotes: 1

C B J
C B J

Reputation: 1858

Taking a quick stab at the problem I'd guess that you need to define a new resource for XXHDPI (The S4 and Htc One fall into this density bucket). Also check that your layouts are using screen size buckets (not density) and you are defining any "fixed size" resources in terms of dp (or another resolution independent unit).

Upvotes: 1

Related Questions