zhunimagebice
V2EX  ›  Android

Android Studio 中创建自定义控件时使用的.java 文件放在哪个目录下比较好?

  •  
  •   zhunimagebice · Feb 29, 2016 · 15779 views
    This topic created in 3740 days ago, the information mentioned may be changed or developed.

    Android 新人,按《第一行代码》上的例子边敲边学,遇到了这个问题。

    自定义控件的用法是在.xml 文件中加入

    <com.example.daniel.uicustomviews.TitleLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    </com.example.daniel.uicustomviews.TitleLayout>

    那么这个 TitleLayout.java 文件应该放哪里?是放在 /res 目录下还是放在 /java/com.example.xx.xxx 下,或者其他位置?

    10 replies    2016-03-01 12:54:42 +08:00
    Bensendbs
        1
    Bensendbs  
       Feb 29, 2016
    我一般放在 com.example.xx.xxx.widgets 里面
    zhunimagebice
        2
    zhunimagebice  
    OP
       Feb 29, 2016
    @Bensendbs 你好 我更新了问题,请问我这个情况应该放哪里?或者说只要是在 /java 目录下就好 还是 /res 目录下?
    karnaugh
        3
    karnaugh  
       Feb 29, 2016
    肯定是 /java 啊..../res 是放图片 布局文件等等玩意的..
    slowindy
        4
    slowindy  
       Feb 29, 2016
    zhunimagebice
        5
    zhunimagebice  
    OP
       Feb 29, 2016
    @Bensendbs 你好!我知道了,放在 /java/com.example.xx.xxx 成功。谢谢~
    Bensendbs
        6
    Bensendbs  
       Feb 29, 2016
    看你在 xml 中引用的路径应该放在 com.example.daniel.uicustomviews 里面
    zhunimagebice
        7
    zhunimagebice  
    OP
       Feb 29, 2016
    @karnaugh 谢谢~因为在右键添加.java 文件时提示问我放在 /java 还是 /res ,所以有点蒙~
    zhunimagebice
        8
    zhunimagebice  
    OP
       Feb 29, 2016
    @slowindy 谢谢你~
    karnaugh
        9
    karnaugh  
       Feb 29, 2016   ❤️ 1
    @zhunimagebice 看你是在新学吧?推荐你个网站吧.http://training.ptteng.com/#/skill/home#1
    ybjaychou
        10
    ybjaychou  
       Mar 1, 2016
    ..... java 文件放在 res 目录怎么编译!!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3611 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 04:44 · PVG 12:44 · LAX 21:44 · JFK 00:44
    ♥ Do have faith in what you're doing.