ImageView will not show up
In 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);
In 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);
Here's my code pertaining to the 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);
...
I have added TextViews with no problem to llFirstScreen, and I am wondering why ImageView won't show up. I tried even adjusting llFirstScreen's height to WRAP_CONTENT instead of the开发者_如何学C screen's height. All that did was shrink the layout to the two TextViews. It's as if it never added the ImageView. The Logs I put in check out, so I know the code is running. Am I missing anything?
Have you tried changing your LinearLayout.LayoutParams from Scale(80), Scale(80) to something like LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT or something? I've never seen Scale(int) used. If that is a custom method can you post it?
精彩评论