I'm not understanding whats going on, I've been on this for hours. I have a ListView of buttons with an adapter. I have a background set for the buttons, but the buttons don't want to align to the middle of the listView, instead it aligns to the left. All the layout-gravity and gravity settings apply to the title text of the button, not the button itself. Is there anyway I can align the background button, or maybe the whole button to the middle of the listView? Heres my code of such things that are relevant
sports_list.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/SportsList"
android:id="@+id/sport_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_gravity="center"/>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!--<item name="android:background">@drawable/default_background</item> -->
</style>
<style name="SportsList" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">@drawable/custom_button</item>
<item name="android:textSize">20dp</item>
<item name="android:textColor">#fff</item>
</style>
</resources>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/default_background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/choose"
android:textColor="#fff"
android:layout_gravity="center"/>
<ListView
android:id="@+id/list_view_sports"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:layout_marginTop="30dp"
android:dividerHeight="30dp"
android:layout_gravity="center_horizontal" />
</LinearLayout>
and the only important section in my mainactivity.java
public static ArrayAdapter adapter;
String[] sports = {"Baseball", "Football", "Soccer"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new ArrayAdapter(
this,
R.layout.sports_list,
R.id.sport_item,
sports);
ListView listView = (ListView) findViewById(R.id.list_view_sports);
listView.setAdapter(adapter);
}
i would like to center the buttons