Today I was writing an app on Android. There was a LinearLayout with 3 TextViews which fill the screen. I wanted their width to be 1:6:6. So I set the "android:layout_weight" property 1, 6, 6. But it didn't work that way. The first TextView became very big and the other two become very small. Then I guess the "weight" means importance. The smaller the weight is, the larger it will be. So I read a lot and found this method to set the weights of the components in your app:
1. Suppose the size of the screen is X.
2. Count how many views there are in a LinearLayout, here I use my example, 3.
3. Total width: total = 3X.
4. delta = X - total = -2X.
5. Suppose you set the weight of the first TextView to be A.
6. Suppose you want the TextView to be 1/13 of the width of the screen.
7. Then use this formula to solve the value of 'A': X + delta*(A/13) = (1/13)X , A=6
I did like this and got the three weight values: 6, 3.5, 3.5, and I got the result exactly as I wanted, the width of the three TextView is 1:6:6.
Sunday, 23 December 2012
Sunday, 9 December 2012
Simulation of Collision Detection using OpenGL
This is a project that I'm very proud of. We built up a physical world using OpenGL.
Balancing Board
The board is made up of a gridded
X-Z plane, bordered at the sides by border walls. This is the space in which
the ball can roam freely.
Material Selection
This graphical user interface is to
use to select the materials for the ball. It includes metal, wool and plastic
ball material.
Walls
There are two kinds of walls –
border walls and red walls. Border walls are used to hold the ball within the
board. The red walls shown here are strips of X-Y planes of a predefined
length. All walls are of height r, where r is the radius of the ball.
Ball
The ball can only travel in the X-Z
plane. It can be simulated with different materials.
Controls
The balancing board can be tilted in
the x-axis and z-axis by using the mouse. The angular limits in both directions
are ±45°.
Subscribe to:
Posts (Atom)