Android custom layouts

0

How can I make two containers in a layout that I have created? The idea is to try to do something similar to what is highlighted in the following image.

And try to insert something similar in the topLinearLayout of my code

In those boxes I will insert the most profitable value with a green fund and the box that accompanies it with a red fund will show the least profitable value

CODE: XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity"
android:background="@color/background">

<LinearLayout
    android:id="@+id/saldoLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/saldoTextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/saldo"
        android:textColor="@color/letra"
        android:textSize="24sp"
        android:textAlignment="center"/>
</LinearLayout>

<LinearLayout
    android:id="@+id/topLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="125dp"
    android:layout_below="@+id/saldoLinearLayout"
    android:orientation="horizontal">

</LinearLayout>

<LinearLayout
    android:id="@+id/midTableLayout"
    android:layout_width="match_parent"
    android:layout_height="450dp"
    android:layout_below="@+id/topLinearLayout"
    android:orientation="vertical">

    <ListView
        android:id="@+id/lvListaDeBotones"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

</LinearLayout>

<LinearLayout
    android:id="@+id/menuLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/midTableLayout"
    android:orientation="horizontal"
    android:weightSum="3">

    <Button
        android:id="@+id/homeButton"
        style="@style/Widget.AppCompat.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Home" />

    <Button
        android:id="@+id/noticiasButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Noticias"
        tools:ignore="ButtonStyle" />

    <Button
        android:id="@+id/estadoButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Estado"
        tools:ignore="ButtonStyle" />
</LinearLayout>



</RelativeLayout>

JAVA:

public class MainActivity extends AppCompatActivity {

static final String[] TITULOS_BTN =
        new String[] { "IBEX 35", "AENA", "BANCO SABADELL", "BANCO  SANTANDER",
                "CAIXABANK", "GAS NATURAL", "FERROVIAL", "IBERDROLA", "TELEFONICA",
                "AMAZON", "MICROSOFT CORPORATION", "APPLE", "NASDAQ", "ORO", "PETROLEO"};

public ListView lvListaDeBotones;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    lvListaDeBotones = (ListView)findViewById(R.id.lvListaDeBotones);
    MyAdapter mAdapter = new MyAdapter(this, TITULOS_BTN);
    lvListaDeBotones.setAdapter(mAdapter);

    lvListaDeBotones.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Aquí puedes capturar en on Click de la vista que se crea en general.
        }
    });
}

}

    
asked by Eduardo 22.04.2017 в 01:37
source

1 answer

2

Copy and paste the code from the line that I mentioned to create as many as you need. Remember to add text to the TextViews, change the color, add the text and the size of the font you want.

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"
    tools:context=".MainActivity"
    android:background="@color/background">

    <LinearLayout
        android:id="@+id/saldoLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/saldoTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/saldo"
            android:textColor="@color/letra"
            android:textSize="24sp"
            android:textAlignment="center"/>
    </LinearLayout>

    <!-- AREA PARA COPIAR INICIO-->
        <LinearLayout
            android:id="@+id/topLinearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_below="@+id/saldoLinearLayout">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:background="@color/colorPrimaryDark"
                android:orientation="vertical"
                android:layout_weight="1"
                android:layout_marginEnd="10dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="20sp"
                    android:text="Turn over"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:text="Turn over"
                    android:textSize="20sp"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:background="@color/colorPrimaryDark"
                android:orientation="vertical"
                android:layout_weight="1">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="20sp"
                    android:text="Turn over"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:text="Turn over"
                    android:textSize="20sp"/>
            </LinearLayout>

    </LinearLayout>
   <!-- AREA PARA COPIAR FIN -->

    <LinearLayout
        android:id="@+id/midTableLayout"
        android:layout_width="match_parent"
        android:layout_height="450dp"
        android:layout_below="@+id/topLinearLayout"
        android:orientation="vertical">

        <ListView
            android:id="@+id/lvListaDeBotones"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/menuLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/midTableLayout"
        android:orientation="horizontal"
        android:weightSum="3">

        <Button
            android:id="@+id/homeButton"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Home" />

        <Button
            android:id="@+id/noticiasButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Noticias"
            tools:ignore="ButtonStyle" />

        <Button
            android:id="@+id/estadoButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Estado"
            tools:ignore="ButtonStyle" />
    </LinearLayout>

    </RelativeLayout>

Let me know if it worked for you.

    
answered by 22.04.2017 / 02:05
source