2017-05-22 7 views
0

私はGoogleアンドロイドのゲームサンプルで作業しようとしていますが、ゲームには1つのアクティビティと1つのxmlレイアウトがあります。アンドロイドxmlで複数のレイアウトを扱うのは難しい

XMLには多くの直線レイアウトがあり、それぞれがゲームの画面を表します。たとえば、「再生」ボタンをクリックすると、すべてのレイアウトが表示されなくなり、「再生画面」レイアウトが表示されるようになります。

私は主なアクティビティを別にすることはできません。なぜなら、私のプロジェクト(アクティビティでバイラルを共有すること)に多くの問題があるからです。だから、私は1つのアクティビティと1つのXMLにとどまる必要があると思う。

主な問題は、アンドロイドスタジオでは私はxmlデザインを見ることができません。 結論私はアンドロイドスタジオでゲームを簡単にデザインし、サンプルプロジェクトを引き続き使用したいと思っています。

私の人生を楽にするアイデアはありますか?

ありがとうございます!

enter image description here xmlファイル:

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout 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" > 

    <!-- SIGN-IN SCREEN --> 
    <LinearLayout android:id="@+id/screen_sign_in" style="@style/LLScreen"> 
     <TextView style="@style/GameTitle" /> 
     <TextView style="@style/GameBlurb" /> 

     <Button android:id="@+id/button_single_player" 
      style="@style/MainScreenButton" 
      android:text="@string/single_player" /> 
     <com.google.android.gms.common.SignInButton android:id="@+id/button_sign_in" 
      style="@style/SignInButton" /> 
    </LinearLayout> 

    <!-- MAIN SCREEN --> 
    <LinearLayout android:id="@+id/screen_main" style="@style/LLScreen"> 
     <TextView style="@style/GameTitle" /> 
     <Button android:id="@+id/button_single_player_2" 
      style="@style/MainScreenButton" 
      android:text="@string/single_player" /> 
     <TextView style="@style/MainScreenButtonBlurb" 
      android:text="@string/single_player_explanation" /> 
     <Button android:id="@+id/button_quick_game" 
      style="@style/MainScreenButton" 
      android:text="@string/quick_game" /> 
     <TextView style="@style/MainScreenButtonBlurb" 
      android:text="@string/quick_game_explanation" /> 
     <Button android:id="@+id/button_invite_players" 
      style="@style/MainScreenButton" 
      android:text="@string/invite_players" /> 
     <TextView style="@style/MainScreenButtonBlurb" 
      android:text="@string/invite_players_explanation" /> 
     <Button android:id="@+id/button_see_invitations" 
      style="@style/MainScreenButton" 
      android:text="@string/see_invitations" /> 
     <TextView style="@style/MainScreenButtonBlurb" 
      android:text="@string/see_invitations_explanation" /> 
     <Button android:id="@+id/button_sign_out" 
      style="@style/SignOutButton" 
      android:text="@string/sign_out" /> 
    </LinearLayout> 

    <!-- INVITATION POPUP --> 
    <LinearLayout android:id="@+id/invitation_popup" style="@style/InvPopup"> 
     <TextView android:id="@+id/incoming_invitation_text" style="@style/InvPopupText" /> 
     <Button android:id="@+id/button_accept_popup_invitation" 
      style="@style/InvPopupButton" 
      android:text="@string/accept_popup_invite" /> 
    </LinearLayout> 

    <!-- "PLEASE WAIT" SCREEN --> 
    <LinearLayout android:id="@+id/screen_wait" style="@style/LLScreen"> 
     <TextView style="@style/Blurb" android:text="@string/please_wait" /> 
    </LinearLayout> 

    <!-- GAMEPLAY SCREEN --> 
    <LinearLayout android:id="@+id/screen_game" style="@style/LLScreen"> 
     <TextView android:id="@+id/instructions" 
      style="@style/Instructions" android:text="@string/instructions" /> 
     <TextView android:id="@+id/my_score" style="@style/ScoreDisplay" /> 
     <Button android:id="@+id/button_click_me" 
       style="@style/GameButton" 
       android:text="@string/click_me" 
       android:layout_marginBottom="20dp" /> 
     <TextView android:id="@+id/countdown" style="@style/FigureLabel" /> 

     <LinearLayout style="@style/ScoresBox"> 
      <TextView android:id="@+id/score0" style="@style/ScoreText" /> 
      <TextView android:id="@+id/score1" style="@style/ScoreText" /> 
      <TextView android:id="@+id/score2" style="@style/ScoreText" /> 
      <TextView android:id="@+id/score3" style="@style/ScoreText" /> 
     </LinearLayout> 
    </LinearLayout> 
</FrameLayout> 

編集 -を私はちょうどレイアウトにandroid:visibility="visible"を追加するために必要な、問題を解決しました。ありがとう。

+0

これは奇妙なデザインの一種です。このコードはどこから入手できましたか? –

+0

@DillonBurton https://github.com/playgameservices/android-basic-samples – Idon89

+0

下記の回答をご覧ください。私はこのように動作しますが、同じフレームレイアウトにすべてを配置すると、個々の画面を編集することは本当に難しくなります。 –

答えて

1

ネストされたレイアウトを避けるには、代わりにConstraintLayoutを使用してください。 Viewsに基づいて、さらに親のレイアウトに基づいて、それぞれViewをルールに揃​​えることができます。

しかし、それを使用するために、あなたはあなたのgradle.buildファイルに依存関係を追加する必要があります。あなたのグローバルのGradleファイルで

dependencies { 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
} 

そしてMaven Repository:ここ

repositories { 
    maven { 
     url 'https://maven.google.com' 
    } 
} 

はサンプルです:

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView6" 
    android:layout_marginStart="16dp" 
    android:layout_marginTop="16dp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginLeft="16dp" /> 

<TextView 
    android:text="TextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView33" 
    android:layout_marginStart="16dp" 
    android:layout_marginTop="16dp" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintLeft_toRightOf="@+id/imageView6" 
    android:layout_marginLeft="16dp" /> 

<TextView 
    android:text="TextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView34" 
    app:layout_constraintRight_toRightOf="@+id/textView33" 
    android:layout_marginTop="8dp" 
    app:layout_constraintTop_toBottomOf="@+id/textView33" /> 

それについての詳細を学ぶために:

https://developer.android.com/training/constraint-layout/index.html

https://codelabs.developers.google.com/codelabs/constraint-layout/index.html

0

あなたは何も表示されない理由ですコメントであなたのルートレイアウトFrameLayoutを置きます。

<!--を2行目に削除します。

+0

私はスタック質問のためだけにxmlからメモを削除しましたが、<! - 。実際のコードでは、その罰金(。また、質問を編集します。 – Idon89

0

私は問題を解決しました。レイアウトにandroid:visibility = "visible"を追加するだけでした。ありがとう。

関連する問題