ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android-设置包括的布局属性

2019-11-02 23:28:11  阅读:158  来源: 互联网

标签:android-layout android


在我的Android应用中,我在一个单独的XML文件中声明一个自定义视图.

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

然后,我有main.xml文件,其中要包含上述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>

如您所见,我正在尝试设置包含视图的layout_toRightOf属性,但未设置,正如我在hierarchyviewer中所见

另一方面,如果我只是简单地将download_interval_setter.xml文件的内容复制粘贴到main.xml并在其中声明layout_toRightOf参数,则视图将根据需要定位在的右边.

我要去哪里错了?
谢谢

解决方法:

因此,我找到了答案here.

标签:android-layout,android
来源: https://codeday.me/bug/20191102/1994962.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有