English 中文(简体)
• 如何确定图象Button的大小,当纽特州受到压力时,就显示其形象。
原标题:How to set ImageButton size and when button is pressed show it on added image
  • 时间:2012-05-04 06:00:55
  •  标签:
  • java
  • android

这里使用的是制作图像Button的法典。 我的所有县都将充满活力地建立起来。

        //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());

首先是我的系统。 排出<<>条码>,直线0和 but吨高0,但装置一看其大于一意。

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>

So how to change my ImageButton size depending maybe on ScrollView size. Also how to show that button is pressed ?

感谢。

问题回答

引言

Drawable dr = getResources().getDrawable(R.drawable.somedrawable); Bitmap bitmap = ((BitmapDrawable) dr).getBitmap(); // Suppose you want to set the size as 50x50 Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 50, 50, true));

你也可以使用。 c 博茨瓦纳(0、0、50、50); 但有些情景可能不利于某些形象。 使用这两种设备。

如需检查,请使用选定器和组件;在您的xml. 帮助





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签