2017-06-26 154 views
0

我有我的佈局問題。當你回答問題時,我有一個textview可以改變文本。所有問題文本和答案文本都在聯機數據庫中,並且我已經正確下載了所有文本。按鈕消失當textview文本更改

問題是,當您正確回答問題時,必須更改問題文本和答案文本。有時它很好,但有時答案按鈕消失。

任何人都可以幫助我嗎?我把下面的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.prodintec.am_motion.QuizActivity"> 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/HeaderTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="20dp" 
     android:text="FOUR OPTIONS QUESTION" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentStart="true" /> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingTop="20dp" 
     android:paddingEnd="10dp" 
     android:paddingStart="10dp" 
     android:layout_below="@+id/HeaderTextView" 
     android:layout_alignParentStart="true"> 


     <TableRow 
      android:padding="2dp" 
      android:id="@+id/tableRow2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <Button 
       android:id="@+id/answer1" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:layout_gravity="center" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_marginBottom="2dp" 
       android:background="@color/primary" 
       android:textColor="@color/accent" 
       android:textSize="10dp" 
       android:text="ANSWER 1" /> 

      <Button 
       android:id="@+id/answer2" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:layout_gravity="center" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_marginBottom="2dp" 
       android:background="@color/primary" 
       android:textColor="@color/accent" 
       android:textSize="10dp" 
       android:text="ANSWER 2" /> 
     </TableRow> 

     <TableRow 
      android:padding="2dp" 
      android:id="@+id/tableRow3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <Button 
       android:id="@+id/answer3" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:layout_gravity="center" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_marginBottom="2dp" 
       android:background="@color/primary" 
       android:textColor="@color/accent" 
       android:textSize="10dp" 
       android:text="ANSWER 3" /> 

      <Button 
       android:id="@+id/answer4" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:layout_gravity="center" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_marginBottom="2dp" 
       android:background="@color/primary" 
       android:textColor="@color/accent" 
       android:textSize="10dp" 
       android:text="ANSWER 4" /> 
     </TableRow> 

     <TableRow 
      android:padding="2dp" 
      android:id="@+id/tableRow4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/HeaderTextView2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="SEE ACRONYM BUTTON FOR MORE INFORMATION" /> 
     </TableRow> 
    </TableLayout> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:paddingStart="10dp"> 

     <TableRow 
      android:padding="2dp" 
      android:id="@+id/tableRow6" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <Button 
       android:id="@+id/acronism" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:padding="5dp" 
       android:background="@color/primary" 
       android:textColor="@color/accent" 
       android:textSize="20dp" 
       android:text="ACRONYM" /> 
     </TableRow> 
    </TableLayout> 

    <TextView 
     android:id="@+id/PointsTextView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:padding="5dp" 
     android:text="POINTS: " 
     android:textAlignment="textEnd" /> 
</RelativeLayout> 

</android.support.constraint.ConstraintLayout> 

我把兩張圖片,第一是所有正確顯示:

enter image description here 第二不:

enter image description here

我認爲這是重要提示說,這個問題只發生在我更改佈局時,第一次將textview放入tablelayout中,但它使得大小問題在屏幕邊界附近切割文本。有了這個新的佈局,我解決了這個問題,但我現在還有其他問題。

+0

只是用戶線性佈局insted的相對佈局 –

+0

我現在使用的LinearLayout的]和它去所有在屏幕的右邊框:/ – Imrik

+0

可以粘貼的佈局圖像你想創建,所以我會給你發送代碼設計 –

回答

1

試試這個我的朋友

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:fillViewport="true" 
    android:layout_height="match_parent"> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/HeaderTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentStart="true" 
     android:text="FOUR OPTIONS QUESTIOgfgfdgdfgdfhghdfghdfjghjdfhgjdfhgjkhdfjghjdfjhgjdhfgjfhddgjhdfjghdjfghjdfhgjfdhgjhdfjghfdjghfdjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjheuireuiwN" 
     android:textSize="20dp" /> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/HeaderTextView" 
     android:paddingEnd="10dp" 
     android:paddingStart="10dp" 
     android:paddingTop="20dp"> 


     <TableRow 
      android:id="@+id/tableRow2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="2dp"> 

      <Button 
       android:id="@+id/answer1" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" 
       android:layout_marginBottom="2dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_weight="1" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:text="ANSWER 1" 
       android:textSize="10dp" /> 

      <Button 
       android:id="@+id/answer2" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" 
       android:layout_marginBottom="2dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_weight="1" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:text="ANSWER 2" 
       android:textSize="10dp" /> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="2dp"> 

      <Button 
       android:id="@+id/answer3" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" 
       android:layout_marginBottom="2dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_weight="1" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:text="ANSWER 3" 
       android:textSize="10dp" /> 

      <Button 
       android:id="@+id/answer4" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" 
       android:layout_marginBottom="2dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_weight="1" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:text="ANSWER 4" 
       android:textSize="10dp" /> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="2dp"> 

      <TextView 
       android:id="@+id/HeaderTextView2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="SEE ACRONYM BUTTON FOR MORE INFORMATION" /> 
     </TableRow> 
    </TableLayout> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:paddingStart="10dp"> 

     <TableRow 
      android:id="@+id/tableRow6" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="2dp"> 

      <Button 
       android:id="@+id/acronism" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:padding="5dp" 

       android:text="ACRONYM" 
       android:textSize="20dp" /> 
     </TableRow> 
    </TableLayout> 

    <TextView 
     android:id="@+id/PointsTextView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:padding="5dp" 
     android:text="POINTS: " 
     android:textAlignment="textEnd" /> 
</RelativeLayout> 
</ScrollView> 
</LinearLayout> 
+0

它工作正常,非常感謝!!!!! :) – Imrik

+0

最受歡迎@Imrik –

+0

我使用此佈局時有更多的問題和答案,我遇到問題。當textview或按鈕的文本長於3行時,它只寫入前三行,但下一行被忽略。你能再幫我一次嗎? @Nilesh Rathod – Imrik