我即将设置ImageView
与setImageResource
,但它不起作用。没有错误。和logcat似乎很好。setImageResource not working
这里是我的代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_item_list_request, container, false);
setHasOptionsMenu(true);
View anotherView = inflater.inflate(R.layout.style_fragment_list_request,container,false);
imgView = (CircleImageView)anotherView.findViewById(R.id.listPhoto);
imgView.setImageResource(R.drawable.pastel_red);
}
考虑到我打了个电话,从另一个布局声明ImageView
。如果我膨胀2布局只是为另一个布局的设置图像是问题?
这里有什么问题吗?
是否在inflat和设置图像资源之后将其他视图布局添加到主布局? –
不,我先膨胀另一个视图然后我设置图像。 查看视图= inflater.inflate(R.layout.fragment_item_list_request,container,false); setHasOptionsMenu(true); 查看anotherView = inflater.inflate(R.layout.style_fragment_list_request,container,false); imgView =(CircleImageView)anotherView.findViewById(R.id.listPhoto); imgView.setImageResource(R.drawable.pastel_red); } – Borom1r
你必须添加anotherView,否则不会显示。 –