在OnCreate中:
svMaster = (ScrollView) findViewById(R.id.scroller); //Only layout in XML file
svMaster.setVerticalFadingEdgeEnabled(false);
Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
height = display.getHeight();
...
initializeGUI();
svMaster.removeAllViews();
svMaster.addView(llMaster);
在initializeGUI()中:
llMaster = new LinearLayout(this); //Only direct child of scrollview
LinearLayout llFirstScreen = new LinearLayout(this); //First layout added to llMaster;
//It's size is that of one screen
LinearLayout.LayoutParams lpMaster = new LinearLayout.LayoutParams
(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
LinearLayout.LayoutParams lpFirstScreen = new LinearLayout.LayoutParams
(LayoutParams.MATCH_PARENT, height);
llMaster.setLayoutParams(lpMaster);
llMaster.setOrientation(LinearLayout.VERTICAL);
llFirstScreen.setLayoutParams(lpFirstScreen);
llFirstScreen.setBackgroundResource(R.color.blue2);
llFirstScreen.setOrientation(LinearLayout.VERTICAL);
这是我与ImageView有关的代码:
ImageView ivWeather = new ImageView(this);
LinearLayout.LayoutParams ivWeatherParams = new LinearLayout.LayoutParams
(Scale(80), Scale(80);
ivWeather.setImageResource(R.drawable.sunny);
Log.d("ImageView loading?", "I hope so");
ivWeather.setScaleType(ScaleType.FIT_XY);
ivWeather.setLayoutParams(ivWeatherParams);
ivWeather.setVisibility(View.VISIBLE); //This is code I tried
ivWeather.setFocusable(true); //when it wouldn't show up
ivWeather.setFocusableInTouchMode(true); //...
ivWeather.invalidate(); //...
...
llFirstScreen.addView(ivWeather);
Log.d("ImageView loading?", "I hope so");
llMaster.addView(llFirstScreen);
...
我已经向llFirstScreen添加了没有问题的TextViews,我想知道为什么使用ImageView 不会出现。我甚至尝试将llFirstScreen的高度调整为WRAP_CONTENT而不是屏幕的高度。所做的只是将布局缩小为两个TextView。就好像它从未添加过ImageView一样。我签入的日志,所以我知道代码正在运行。 我错过了什么吗?
答案 0 :(得分:0)
您是否尝试将ScaleLayout.LayoutParams从Scale(80),Scale(80)更改为LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT等等?我从未见过使用过Scale(int)。如果这是一个自定义方法,你可以发布吗?