2017-10-20 20 views
-1
<TextView 
    android:id="@+id/textViewGuessGame" 
    android:layout_width="wrap_content" 
    android:layout_height="36dp" 
    android:text="Guess Game" 
    android:textSize="24sp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    tools:layout_editor_absoluteY="6dp" /> 

<TextView 
    android:id="@+id/textViewGameRules" 
    android:layout_width="wrap_content" 
    android:layout_height="61dp" 
    android:text="Game rules: guess the wrong number and you loose a point. Guess the right number and get one point " 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintHorizontal_bias="0.13" 
    tools:layout_editor_absoluteY="54dp" /> 

<TextView 
    android:id="@+id/textViewResult" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    android:text="Points : 0 " 
    tools:layout_editor_absoluteY="233dp" 
    app:layout_constraintHorizontal_bias="0.455" /> 

<Button 
    android:id="@+id/buttonL" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:text="0" 
    tools:layout_editor_absoluteX="37dp" 
    tools:layout_editor_absoluteY="146dp" /> 

<Button 
    android:id="@+id/buttonR" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:text="0" 
    tools:layout_editor_absoluteX="208dp" 
    app:layout_constraintBaseline_toBaselineOf="@+id/buttonL" /> 

安卓工作室,頂部的所有文字和按鈕。我該如何解決?

我想讓它這樣兩個按鈕去旁邊,彼此文本視圖遊戲規則textviewguessgame下。我正在努力讓它們不會在左側的角落裏一齊放在一起。有沒有我可以看的視頻,所以我不必每次都繼續提問?

+1

什麼是您的佈局?另見[this](https://stackoverflow.com/questions/22160842/what-is-the-android-equivalent-of-this-xaml-grid)SO問題。 –

回答

0

一切都取決於您使用的佈局。看起來你正在使用ConstraintLayout,但你並沒有複製所有的xml代碼。我推薦RelativeLayout,在RelativeLayout中事情並不複雜,它用於爲不同的屏幕尺寸製作佈局。

這裏是Android開發者關於RelativeLayout的官方網頁教程。 https://developer.android.com/guide/topics/ui/layout/relative.html

有時你想使用另一種佈局,但在你的情況下,RelativeLayout將會很好。

+0

是啊,感謝您的信息。我只是想知道這是一個糟糕的問題? –

+0

我沒有投票,因爲我曾經在Android中遇到過佈局問題,雖然這是一個糟糕的問題,但在xml中觀看一些關於android佈局的教程,在YouTube上有很多。這只是一開始就很難。祝你好運! –

+0

謝謝,我希望自從我還是個孩子以來,編碼一直是個夢想。 –

0

根據您的佈局規格,我認爲垂直方向的線性佈局是最好的協議。請嘗試下面的代碼。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <TextView 
     android:id="@+id/textViewGuessGame" 
     android:layout_width="wrap_content" 
     android:layout_height="36dp" 
     android:gravity="center" 
     android:layout_gravity="center" 
     android:text="Guess Game" 
     android:textSize="24sp"/> 

    <TextView 
     android:id="@+id/textViewGameRules" 
     android:layout_width="wrap_content" 
     android:layout_height="61dp" 
     android:padding="5dp" 
     android:text="Game rules: guess the wrong number and you loose a point. Guess the right number and get one point " /> 

    <TextView 
     android:id="@+id/textViewResult" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Points : 0 "/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="center"> 
     <Button 
      android:id="@+id/buttonL" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="0" /> 

     <Button 
      android:id="@+id/buttonR" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="0"/> 

    </LinearLayout> 

</LinearLayout> 
+0

謝謝!對不起,如果這是一個愚蠢的問題,並感謝回覆。 –