ImageButtonの作成に使用しているコードは次のとおりです。私のすべてのボタンは動的に作成されます。それでは、どのように私のImageButtonのサイズを変更するにはImageButtonのサイズを設定する方法とボタンを押したときの画像の追加方法
LinearLayout pubLayout = (LinearLayout)findViewById(R.id.myFilesScrollerLayout);
pubLayout.addView(button);
<ScrollView
android:id="@+id/myFilesScroller"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
>
<LinearLayout
android:id="@+id/myFilesScrollerLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
:すべての
//It is button which inherits from ImageView
ImageButton button = new ImageButton(this);
Drawable testPic = getResources().getDrawable(R.drawable.test_pic);
//button.setBackgroundColor(R.color.transparent_background);//transparent image button button background
//button.setImageDrawable(testPic);
button.setBackgroundDrawable(testPic);
//button.setMaxWidth(20);
button.setOnClickListener(mCorkyListener);
button.setTag(i);
//button.setId(i);
//Controls how the image should be resized or moved to match the size of this ImageView.
button.setScaleType(ScaleType.CENTER_INSIDE);
System.out.println("button with "+button.getMeasuredWidth());
System.out.println("button height "+button.getMeasuredHeight());
まず私のSystem.outはbutton with 0 and button height 0
を返すが、デバイス上で、私は私が望むよりも大きいことがわかり、私はScrollviewにこのボタンを配置しましたおそらくScrollViewのサイズに依存します。そのボタンが押されたことを示す方法も?
ありがとうございました。 。
しかし、私はImageButtonの背景色を透明にし、イメージを置く。それで彼がそのイメージを押したことをユーザーに示す方法は?私のすべてのボタンは動的に作成されていますが、私はそれらのxmlを持っていません – Streetboy