Doubt game two players, half screen upside down

Asked

Viewed 330 times

8

I am creating a program to practice what I have learned so far and learn more, but I have reached a halt. The doubt is as follows:

I’m creating a question and answer game for two players, each one stands on one side of the mobile to play, the layout desired would be something like the photo below:

meu_layout

But I don’t know how to make that top half (yellow part) stick with things appearing from upside-down, has some way of using a Fragment and rotate it? Or some personal idea?

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

3 answers

7

I got it guys, I found very little content about it, but it’s pretty basic, I just divided the screen into two Relativelayouts and I used a simple xml attribute, android:rotation="180" Follow below as the code. (I think it would be better if I had used two Ragments, 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>

7


I suggest using that custom layout: Rotate Layout

Its use according to the creator is quite simple, just arrange in your gradle

the repository:

repositories {
    jcenter()
}

and the dependency:

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

done that, arrange in your layout the following lines:

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

1

It seems to me that each part will have an individual functionality ? You can use an Activity, and popular it with two Fragments, then you specify the orientation of each Fragment. This question (in English) shows how to force a screen orientation.

Edit (Content of the link):

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

Other fragments which shall not be "caught" shall contain getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); thus remains with the initial configuration.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.