2011-08-10 6 views
1

を表示されません。initializeGUIでImageViewのは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); 

を():

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に調整してみました。 2つのTextViewにレイアウトを縮小しただけです。 ImageViewを追加したことがないかのようです。私がチェックアウトしたログは、コードが実行されていることを知っています。 何も分からないのですか?

答えて

0

LinearLayout.LayoutParamsをScale(80)、Scale(80)からLayoutParams.WRAP_CONTENT、LayoutParams.FILL_PARENTなどに変更しようとしましたか? Scale(int)が使用されたことは一度もありません。それがカスタムメソッドであれば投稿できますか?

+0

scale = this.getApplication()。getResources()。getDisplayMetrics()。密度; // dpsに変換 \t private int Scale(int i){ \t \t i =(int)((float)i * scale + 0.5f); \t \t return i; \t} これは当たり前... おかげであなたは私はスケール変数を必要とするカスタムスケールの方法を使用した後、私は、スケール変数を初期化することを実感しました DPSに – user888888

+0

lollolを整数に変換する方法である – user888888

+0

恐ろしい:)うれしいI助けることができます – Jack

関連する問題