Android Question How to use xml layout

Schakalaka

Active Member
Licensed User
Longtime User
hello,
i have see that is possible use android xml layout in b4a with XmlLayoutBuilder - Load Xml layouts
my question is.
how can i adapt this xml file to use it? there is relative and linear layout.
i have always used only the designer and set sizes by script...
example1:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rl_cat"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:orientation="vertical"
    android:layout_marginStart="7dp"
    android:layout_marginEnd="7dp">

    <com.makeramen.roundedimageview.RoundedImageView
        android:id="@+id/iv_cat"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/placeholder_cat"
        app:riv_corner_radius="70dp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg_circle_black80"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_cat_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:maxLines="1"
            android:minLines="1"
            android:textSize="14sp"
            android:textColor="@color/white"/>

        <TextView
            android:id="@+id/tv_cat_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:maxLines="1"
            android:minLines="1"
            android:textSize="10sp"
            android:textColor="@color/white"/>

    </LinearLayout>

</RelativeLayout>

Example2:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rl"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.makeramen.roundedimageview.RoundedImageView
        android:id="@+id/iv_vp_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        app:riv_corner_radius="10dp"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:background="@drawable/bg_grt_black_round_bottom"/>

    <TextView
        android:id="@+id/tv_pager_cat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:padding="10dp"
        android:textSize="16sp"
        android:layout_margin="10dp"
        android:layout_toLeftOf="@+id/button_pager_fav"
        android:layout_toStartOf="@+id/button_pager_fav"
        android:layout_alignParentBottom="true"/>

    <com.like.LikeButton
        android:id="@+id/button_pager_fav"
        android:layout_width="50dp"
        android:layout_height="50dp"
        app:like_drawable="@mipmap/fav_hover"
        app:unlike_drawable="@mipmap/fav"
        app:circle_end_color="@color/colorPrimary"
        app:circle_start_color="@color/red"
        app:dots_primary_color="@color/colorPrimary"
        app:dots_secondary_color="@color/red"
        app:icon_size="30dp"
        app:anim_scale_factor="2"
        app:is_enabled="true"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginBottom="5dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

example3:

B4X:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_cat"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="7dp" />

    <TextView
        android:id="@+id/tv_empty_cat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="20dp"
        android:text="@string/no_data_found"
        android:textColor="@color/white"
        android:layout_centerInParent="true"
        android:visibility="gone" />

    <fr.castorflex.android.circularprogressbar.CircularProgressBar
        android:id="@+id/pb_cat"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        android:indeterminate="true"
        android:visibility="gone"
        app:cpb_color="#FFee44"
        app:cpb_colors="@array/pocket_bar_colors"
        app:cpb_max_sweep_angle="300"
        app:cpb_min_sweep_angle="10"
        app:cpb_rotation_speed="1.0"
        app:cpb_stroke_width="4dp"
        app:cpb_sweep_speed="1.0" />

</RelativeLayout>
 

Schakalaka

Active Member
Licensed User
Longtime User
ok, i will, but what mean this code?
B4X:
android:layout_width="match_parent"
android:layout_height="wrap_content"

How to translate it for designer?

Can i set for an activity more layout parts?

all this example are parts off the same activity;

Can i set for ex.

Toolbar layou = file 1
Body layout => listview, amirrecycleview, or other = file layout2

bottom menu layout = file layout 3


Layout activity = file1+ file 2+ file 3

i' m try to recreate an android studio app in b4a.
this is the full project, as you can understand better what i 'd like to do, and help me? (if you want of course).
B4X:
https://drive.google.com/file/d/1uzD4vpeJ1iRg32bBIk3MQPZyrIXtZCYl/view?usp=sharing
 
Upvote 0
Top