Doubt two player game, half screen upside down

8

I am creating a program to practice what I have learned so far and to learn more, but I have reached a stalemate. The question is:

I'm creating a question and answer game for two players, each one stands on one side of the phone to play, the desired layout would look something like the picture below:

But I do not know how to make that top half (yellow part) get things popping up , have some way of using a fragment and rotate it? Or any personal ideas?

Detail, the two parts can be the same, only the top one upside down.

    
asked by anonymous 09.06.2016 / 02:16

3 answers

7

I suggest using this custom layout : Rotate Layout

Its use according to the creator is quite simple, just tidy up your gradle

the repository :

repositories {
    jcenter()
}

and dependency :

dependencies {
    compile 'rongi.rotate-layout:rotate-layout:2.0.0'
}

Once this is done, set up the following lines in your layout :

<com.github.rongi.rotate_layout.layout.RotateLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_content"
    android:layout_height="match_content"
    app:angle="180"> <!-- Nessa linha o angulo que você deseja -->

    <LinearLayout <!-- Aqui altere pelo seu layout -->
        android:layout_width="match_content"
        android:layout_height="match_content">
    </LinearLayout>

</com.github.rongi.rotate_layout.layout.RotateLayout>
    
09.06.2016 / 13:29
7

I've got people, I found very little content about it, but it's pretty basic, I just split the screen into two RelativeLayouts and I used a simple xml attribute, android: rotation="180" Here's how the code looks. (I think it would look better if I had used two fragments, but I'm still learning how to use them)

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

<RelativeLayout
    android:id="@+id/Relative1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#FFF111"
    android:rotation="180">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/buttonP2"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="100dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Pergunta:"
        android:id="@+id/textViewPergunta2"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Placar"
        android:id="@+id/textViewPlacar2"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/Relative2"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="0dp"
    android:background="#FF0000">


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/buttonP1"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="100dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Pergunta:"
        android:id="@+id/textViewPergunta1"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Placar"
        android:id="@+id/textViewPlacar1"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

    
09.06.2016 / 20:07
1

It seems to me that each part will have an individually appropriate functionality? You can use an activity, and popular it with two fragments, then you specify the orientation of each fragment. This question shows you how to force a screen orientation.

Edit (Link content):

You can programmatically specify which screen orientation you want, just put getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); or getActivity().setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); to lock the screen upside down.

The other fragments that will not be "locked", must contain getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); in this way, it remains with the initial configuration.

    
09.06.2016 / 19:23