Installation layout attribute for include

In my Android application, I declare a custom view in a separate XML file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
android:id="@+id/download_interval_setter" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<Button 
    android:layout_height="wrap_content"  
    android:layout_width="wrap_content" 
    android:id="@+id/Button_interval_up"
    style="?android:attr/buttonStyleSmall">
</Button>
<EditText 
    android:id="@+id/Download_interval" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:text="1"
    android:numeric="integer">
</EditText>
<Button 
    android:id="@+id/Button_interval_down"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
</Button>
</LinearLayout>

Then I have a main.xml file where I would like to include the view declared above in XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ToggleButton android:layout_height="wrap_content" 
        android:id="@+id/XMLStart" 
        android:textOn="@string/auto_update_on"
        android:textOff="@string/auto_update_off" 
        android:layout_width="wrap_content" />
<include layout="@layout/download_interval_setter"
        android:layout_toRightOf="@id/XMLStart"/>
<Button android:layout_height="wrap_content" 
        android:id="@+id/ShowRadars" 
        android:text="@string/show_radars" 
        android:layout_width="wrap_content" 
        android:layout_below="@id/XMLStart"/>       
<Button android:layout_height="wrap_content" 
        android:id="@+id/ShowAccidents" 
        android:text="@string/show_accidents" 
        android:layout_width="wrap_content" 
        android:layout_toRightOf="@id/ShowRadars"
        android:layout_below="@id/XMLStart"/>
<Button android:layout_height="wrap_content" 
        android:id="@+id/ShowConstraints" 
        android:text="@string/show_constraints" 
        android:layout_width="wrap_content" 
        android:layout_below="@id/ShowRadars"/>     
<Button android:layout_height="wrap_content" 
        android:id="@+id/ShowPatrols" 
        android:text="@string/show_patrols" 
        android:layout_width="wrap_content" 
        android:layout_below="@id/ShowRadars"
        android:layout_toRightOf="@id/ShowConstraints"/>    
</RelativeLayout>

As you can see, I am trying to set the layout_toRightOf attribute of the included view, but it is not set, as I see also in the hierarchyviewer file

On the other hand, if I just copy the contents of the download_interval_setter.xml file into main.xml and declare the layout_toRightOf parameter there, the view will be located to the right of it, as I want.

Where am I mistaken? Thanks

+3
source share
2 answers

So, I found the answer here .

+4
source

RelativeLayout XML , android:layout_toRightOf LinearLayout.

0

Source: https://habr.com/ru/post/1792778/


All Articles