作业帮 > 综合 > 作业

java Android `求这两句的意思

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/05/04 13:35:11
java Android `求这两句的意思
tabLayout = (LinearLayout) this.findViewById(R.id.TabLayout);
tabLayout.setBackgroundDrawable(this.getResources().getDrawable(
R.drawable.tab01));
java Android `求这两句的意思
tabLayout = (LinearLayout) this.findViewById(R.id.TabLayout);

这行代码就是根据视图的ID来获取控件对象.
你这行代码的话应该是你的布局文件中有个LinearLayout,它的android:id="@+id/TabLayout".
这样在Activity中通过Activity类的findViewById(R.id.TabLayout)获取次LinearLayout.

tabLayout.setBackgroundDrawable(this.getResources().getDrawable(
R.drawable.tab01));
这行代码就是设置你的布局的背景,就是一张图片.
图片是drawable目录下的tab01.
再问: 解释的很详细 我还想知道 tabLayout前面加LinearLayout是什么意思 LinearLayout tabLayout = (LinearLayout) this.findViewById(R.id.TabLayout); 和 tabLayout = (LinearLayout) this.findViewById(R.id.TabLayout); 有什么不一样 还是都是给 tabLayout 定义?
再答: LinearLayout tabLayout = (LinearLayout) this.findViewById(R.id.TabLayout); ��IJ����ļ���Ӧ����LinearLayout������id��TabLayout������ͨ��findViewById(R.idTabLayout)���ǻ�����LinearLayout����Ϊthis.findViewById()�������ص���һ��View��Ӧ���ǵģ���û����������LInearLayout��������Ҫǿ������ת���� tabLayout = (LinearLayout) this.findViewById(R.id.TabLayout); ���Ӧ�����㶨���˳�Ա����LinearLayout tabLayout�� ������ public class MyActivity extends Activity { private LinearLayout tabLayout = null; public void onCreate(Bundle b) { tabLayout = this.findViewById(R.id.tabLayout); } } �����˲������ִ�ѽ������ɣ�