Layout pixels and Canvas pixels different?



So, I have Framelayout witch has SurfaceView(0), and xml layout(1). My layouts height is 200px(below), and I'm drawing 200px high rectangle for testing. For some wierd reason, layout seems to take up more space tan rectangle. How could I make it so, that layout would be in rectangle, regardless of screen size or density? (I hope this not too confusing...)


Layout:



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="200px"
android:orientation="horizontal"
android:id="@+id/game_ui
"
style="@style/AppTheme">

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
>

<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:text="Points"
android:textSize="30sp"
android:gravity="center"
/>

<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:text="500"
android:textSize="60sp"
android:gravity="center"
/>



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:text="Time"
android:textSize="30sp"
android:gravity="center"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:text="500"
android:textSize="60sp"
android:gravity="center"/>


</LinearLayout>


Drawing a Rectangle:



Graphics g = game.getGraphics();
g.clearScreen(Color.BLACK);
g.drawRect(0, 0, wildth, 200, Color.GREEN);
//draws 200px high rectangle onto surfaceView


Result is this:


http://ift.tt/1sPn4R0


No comments:

Post a Comment