mryj

Android include标签使用需要注意的点

1.include标签设置了id之后就不能直接访问里面的元素了,那应该怎样来访问里面的元素呢,这里用一个简单的例子说明

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
    
         <include layout="@layout/rating_button_relative"
                android:id="@+id/rating_relative"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="@dimen/_20"
                android:visibility="gone"
                ></include>

 </RelativeLayout>

这样设置了id之后要获得布局内的元素,需要这样使用

 View layout = (View)findViewById(R.id.resource_rating_relative);
      layout.setVisibility(View.VISIBLE);
 Button  mMakeRatingBnt=(Button)layout.findViewById(R.id.make_rating_button);
 Button  mLookRatingBnt=(Button)layout.findViewById(R.id.look_rating_button);

除此之外需要注意一点的是,如果需要给include标签设置位置,需要重写layout_width,
layout_height才能起作用,具体为什么我也不知道,有知道的方便的话请告知我,在下不胜感激

 

发表于 2017-03-23 16:10  人若无名便可专心练剑  阅读(793)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2022-02-25
  • 2021-07-30
  • 2021-12-28
  • 2021-04-26
  • 2021-07-15
猜你喜欢
  • 2022-01-23
  • 2021-12-24
  • 2021-12-03
  • 2021-10-24
  • 2021-11-21
  • 2021-07-21
  • 2022-01-07
相关资源
相似解决方案