I cant put a textview above my buttons without having my buttons move...How can I fix this?
Been stuck on this for 4 hours...Which is sad because I'm trying to add a textview on my layout...
I have a layout with 4 buttons in the center. I simply want to add a textview above the four buttons, like illustrated here (TextView should be in the place of the red) :
The drag and drop in the XML layout view will not work when I place the textview above the buttons. It just dis centers the buttons. I also tried doing what this answer suggested, but then the anchor view itself would not be positioned in the center!
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.me.circleswithmap.MainActivity"
android:id="@+id/layout"
android:gravity="center">
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Blue"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/bluesquare" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Green"
android:layout_below="@+id/Blue"
android:layout_alignLeft="@+id/Blue"
android:layout_alignStart="@+id/Blue"
android:background="@drawable/greensquare" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Red"
android:layout_alignTop="@+id/Blue"
android:layout_toRightOf="@+id/Blue"
android:layout_toEndOf="@+id/Blue"
android:background="@drawable/redsquare" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Purple"
android:layout_alignBottom="@+id/Green"
android:layout_alignLeft="@+id/Red"
android:layout_alignStart="@+id/Red"
android:background="@drawable/purplesquare" />
NEED SOME TEXTVIEW ALSO! WHENEVER I ADD ONE, IT DISCENTERS THE REST OF THE BUTTONS!
</RelativeLayout>
What should I do to tackle this problem? Why is it so difficult? Should I not use Relative Layout? How can I stop this from being relative to each other?
Thanks so much,
NullPointerException