2017-10-03 5 views
0

Je suis en train de construire une application de liste pour l'instant et je dois aligner la fois sur le bouton et le texte dans la même ligne, mais comme je suis extrêmement nouveau pour studio Android et Java Je ne parviens pas. tous les guides que j'ai trouvé sont démodés mon code est ci-dessousla mise en place d'un TableLayout

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1" 
    android:strechColumns="1"> 

    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:baselineAligned="false"> 

     <TextView 

      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="Job 1" 
      /> 

    </TableRow> 

    <ToggleButton 
    android:id="@+id/button1" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:onClick="" 
    android:text="test text" 
    /> 
</TableLayout> 

toute aide serait appréciée

Répondre

0

Essayez ci-dessous code à l'intérieur tag:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    > 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="Job 1" 
     /> 
     <ToggleButton 
      android:id="@+id/button1" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:onClick="" 
      android:text="test text" 
     /> 
    /> 
+0

merci pour cela, mais je pense que je vais essayer une approche différente à l'aide des tables semble être la mauvaise façon d'aller à ce –

0

Mettre votre ToggleButton en TableRow mettra vos articles dans la même rangée.

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:weightSum="1" 
android:strechColumns="1"> 

    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:baselineAligned="false"> 

     <TextView 

      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="Job 1"/> 

     <ToggleButton 
      android:id="@+id/button1" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:text="test text"/> 

    </TableRow> 

</TableLayout> 

Alors que d'autres Si vous pouvez obtenir même avec l'aide List/RecyclerView adaptateur si vous avez besoin de deux éléments en ligne, Utilisation Liste/RecyclerView est alors approche simple TableView. Dans votre code XML utilisation de l'adaptateur suivant pour l'article itérations

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <TextView  
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toLeftOf="@+id/toggleButton" 
     android:layout_toStartOf="@+id/toggleButton" 
     android:layout_alignParentleft="true" 
     android:layout_alignParentStart="true" 
     android:text="test "/> 

    <ToggleButton 
     android:id="@+id/toggleButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true"/> 
    </RelativeLayout>