Reputation: 21
In my design portion of my code, I have my spinner in the center or the app, but when I run the application, it appears all the way up top. I looked up ways how to fix this and nothing is working. Can anyone suggest anything?
Here's my XML: https://gist.github.com/liliycode/43e45cd39c765716aebbdea4a4c08b89
And if needed, here is my java:
https://gist.github.com/liliycode/50246841d81a65ec177283ec0a488b52
Upvotes: 0
Views: 51
Reputation: 625
You should take a look at the documentation for questions like this.
As recommended in the documentation here, I usually use Relative Layout
.
The centerInParent
, centerHorizontal
and centerVertical
work perfectly for these cases.
Example, using them:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="American Writers"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:layout_centerHorizontal="true"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/author_names"
android:layout_centerInParent="true">
</Spinner>
</RelativeLayout>
I hope it helps.
Upvotes: 3