ImageButtonを作成するために使用しているコードは次のとおりです。私のボタンはすべて動的に作成されます。
//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 に入れます。
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>
したがって、おそらく ScrollView のサイズに応じて ImageButton のサイズを変更する方法。また、ボタンが押されたことを示す方法は?
ありがとう。