Questions tagged [gravity]

The concept of UI widgets being dragged to a specific side of a surrounding element.

The concept of UI widgets being dragged to a specific side of a surrounding element.

Do not use this to refer to accelerometers (gravity sensors) in mobile phones. Use accelerometer instead.

832 questions
253
votes
7 answers

How set the android:gravity to TextView from Java side in Android

I can use android:gravity="bottom|center_horizontal" in xml on a textview to get my desired results, but I need to do this programmatically. My textview is inside a tablerow if that matters in a relativelayout. I have tried: LayoutParams…
Nate
  • 2,720
  • 2
  • 16
  • 17
111
votes
16 answers

Android Support Design TabLayout: Gravity Center and Mode Scrollable

I am trying to use the new Design TabLayout in my project. I want the layout to adapt to every screen size and orientation, but it can be seen correctly in one orientation. I am dealing with Gravity and Mode setting my tabLayout as: …
Javier Delgado
  • 2,343
  • 2
  • 17
  • 31
95
votes
6 answers

Android center view in FrameLayout doesn't work

I have a FrameLayout in which I have 2 controls: - a custom view which draws a image and some text on it - a textview with a text I want to center both in the FrameLayout but I can't manage to do it. The Texview is centered just fine, my cusom view…
Alin
  • 14,809
  • 40
  • 129
  • 218
70
votes
2 answers

Is it possible to specify multiple gravity values in spinner item custom_style.xml?

I have textview.xml, which is the item style for spinners.
87element
  • 1,909
  • 3
  • 19
  • 29
49
votes
5 answers

Positioning an image inside an ImageView with gravity: top

╔════════════════════════════════════════════════════════╗ ║ Linear Layout (Center) ║ ║ ╔══════════════════════════════════════════════╗ ║ ║ ║ ImageView ╔══════════════╗ …
Nam Vu
  • 5,669
  • 7
  • 58
  • 90
45
votes
7 answers

Setting of ImageView's gravity to the center in android programmatically

I want to set the gravity of an array of Imageviews,ImageIcons[i] to the center with the following code, ImageIcons[i] = new ImageView(this); ImageIcons[i].setLayoutParams(new…
Vivek Kalkur
  • 2,200
  • 2
  • 21
  • 40
29
votes
7 answers

Center text android button

My question is very simple. How do I center the text on a button in android? I tried to set padding to 0, gravity to center but the result when i run it still that the text is horizontal centred but not vertical. The text is a bit shifted to the…
dieters
  • 317
  • 1
  • 4
  • 8
27
votes
8 answers

Center of gravity of a polygon

I am trying to write a PHP function that will calculate the center of gravity of a polygon. I've looked at the other similar questions but I can't seem to find a solution to this. My problem is that I need to be able to calculate the center of…
mixkat
  • 3,883
  • 10
  • 40
  • 58
25
votes
3 answers

Set gravity of a View Programmatically

Im working on a View over Android Source Code. I was wondering how can we setup multiple gravities, to a custom View This is the XML
user809486
  • 888
  • 1
  • 7
  • 15
22
votes
2 answers

What is the difference between "gravity" and "acceleration" sensors in Android?

What is the difference between gravity and acceleration sensors in Android? From my point of view the physical value is the same in both cases. Which one measures the force acting on unit mass inside the device? ADDITION The question is: what…
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
21
votes
4 answers

android remove gravity from accelerometer readings

I am developing an application for Android where I need to remove gravity from accelerometer readings. I have read multiple discussions on this problem, I have also found an algorithm here, but I didn't really understand it. I want to filter gravity…
Gabriel
  • 2,054
  • 4
  • 26
  • 34
20
votes
3 answers

Android - Center Textview in LinearLayout

I am trying to center a TextView in a LinearLayout and it is centering horizontaly but not vertically. below is my code
user222786
  • 547
  • 4
  • 7
  • 17
19
votes
19 answers

Gravity Sort : Is this possible programmatically?

I've been thinking recently on using the Object Oriented design in the sorting algorithm. However I was not able to find a proper way to even come closer in making this sorting algorithm that does the sorting in O(n) time. Ok, here is what I've…
bragboy
  • 34,892
  • 30
  • 114
  • 171
18
votes
6 answers

Android: Edittext with gravity center not working on device

In Android I'm using a single line edittext with gravity set to center. In the Emulator this works great both the hint and a blinking cursor shows up. When testing on device (Xperia X10) neither the hint text nor the blinking cursor shows up. The…
Martin
  • 7,190
  • 9
  • 40
  • 48
18
votes
4 answers

Manage Layout Inside a Horizontal Oriented Radiogroup

I am using a TableLayout with TableRows as my main activity. Inside the TableLayout is a Radio Group containing 2 Radio Buttons inside the activity (the Radio Group being inside a table row). I want to be able to align the rightmost radio button to…
deteego
  • 181
  • 1
  • 1
  • 5
1
2 3
55 56