2012-04-07 104 views
0

其实我是想为我的布局中只包含ImageButtons,试图通过调整大小按钮单击ImageButton的实现在不同的缩放。 但我面临的问题是该按钮内的TableRow膨胀进一步的TableRow在TableLayout膨胀。变化大小动态

LAYOUT1.xml 

<HorizontalScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/TabScrollView" > 

     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <RelativeLayout 
       android:id="@+id/RelativeLayoutTable" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/TabScrollView" 
       android:background="@drawable/blackbackground" > 

       <TableLayout 
        android:id="@+id/elementTable" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_x="2dp" 
        android:layout_y="2dp" 
        android:orientation="horizontal" > 
       </TableLayout> 


       </TableLayout> 
      </RelativeLayout> 
     </ScrollView> 
    </HorizontalScrollView> 

LAYOUT2.xml 

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/elementRow" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

</TableRow> 

LAYOUT3.xml 

<?xml version="1.0" encoding="utf-8"?> 
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/elementImage" 
android:layout_width="100px" 
android:layout_height="100px" 
android:background="@null" 
android:onClick="onClick" 
android:padding="3dip" 
android:scaleType="fitXY" /> 

我尝试使用这个代码

ImageButton ib =(ImageButton)findviewbyId(R.id.elementImage); 
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, height); 
ib.setLayoutParams(layoutParams); 

按钮的大小保持相同的图像的大小。

回答