lundi 29 février 2016

Android studio move check box to right of table cell

I have created a table view inside of a list view in Android studio (see following code) and for various reasons I have used a text view and a checkbox as separate elements rather than just having the checkbox and attaching the text. The problem is the text is on the left of the screen/table but the checkbox is essentially centred where as I want it to be at the far right hand side.

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/title"
    android:layout_above="@+id/Button1"
    android:id="@+id/scrollView"
    android:background="@drawable/list">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/Maths"
        android:id="@+id/Maths"
        android:layout_column="1"
        android:textColor="#ffffff" />
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/MathsCheck"
            android:layout_column="2"
            android:buttonTint="#00ffff"
            android:onClick="MathsClicked"/>
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="@string/History"
            android:id="@+id/History"
            android:layout_column="1"
            android:textColor="#ffffff"/>
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/HistoryCheck"
            android:layout_column="2"
            android:onClick="HistoryClicked"
            android:buttonTint="#00ffff" />
    </TableRow>
</TableLayout>
</ScrollView>

There are in reality a lot more of these text view and checkboxes but you get the idea. I have tried using padding and margins but that doesn't really work as it will work ok on some devices displays but I have to hard code it which isn't ideal. I've also tried the gravity feature which for some reason doesn't seem to do anything.

Any help appreciated




Aucun commentaire:

Enregistrer un commentaire