ImageView、Buttonについて
お早う御座います、
ボタンに画像を貼り付ける方法が分かりません、
詳しい方、宜しくお願い致します。
ボタンに「縮小した画像」を貼り付け、Viewに貼り付けたいのですが、
最後の「imgbtn_1.setImageResource(iv_1);」でエラーが出ます。
色々なサイトを参考にしながら、コードを書きましたが、
エラーの意味も原因もよく分かりません。
宜しくお願い致します。
ajaさん、回答有難う御座います。layoutは設定しています、文字数の関係で省略していました。宜しくお願い致します。
public class MainActivity extends AppCompatActivity
{
ImageView iv_1 ;
ImageButton imgbtn_1 ;
Bitmap bit1 ;
@Override protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ) ; setContentView( R.layout.activity_main ) ; LinearLayout layout = new LinearLayout( this ) ; layout.setOrientation( LinearLayout.VERTICAL ) ; layout.setLayoutParams ( new LinearLayout.LayoutParams ( LinearLayout.LayoutParams.MATCH_PARENT , LinearLayout.LayoutParams.MATCH_PARENT ) ) ; setContentView( R.layout.activity_main ) ; // View ボタンを生成 iv_1 = new ImageView( this ) ; imgbtn_1 = new ImageButton( this ) ; // 200x300にリサイズ bit1 = Bitmap.createScaledBitmap ( BitmapFactory.decodeResource( getResources( ) , R.drawable.img1 ) , 200 , 300 , false ) ; iv_1.setImageDrawable( new BitmapDrawable( getResources() , bit1 ) ) ;
// imgbtn_1.setImageResource(iv_1) ;
}
}
回答1件
あなたの回答
tips
プレビュー