-1

在一个对话框上,我想要一个带有 WRAP_CONTENT 的 ImageButton 左侧的 MATCH_PARENT EditText。这看起来像下面的图片。

版面图片http://goo.gl/dxuS5

我不知道如何解决这个问题!它必须只用java编程!我没有机会用 XML 写这个。

我刚刚使用了 LinearLayout。但是 MATCH_PARENT 将 ImageButton 与 WRAP_CONTENT 交换。我也使用RelativeLayout,但这看起来不像我想要的。

4

2 回答 2

0

尝试这个:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
    <ImageButton
        android:layout_gravity="right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:layout_gravity="left"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
于 2012-05-12T09:51:10.577 回答
0

假设您将这些放入水平方向的 LinearLayout 中:

EditText temp = new EditText(this);
LinearLayout.LayoutParams params = new  LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);                            LayoutParams.WRAP_CONTENT, 1);
temp.setLayoutParams(params);

ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(vp);        
imageView.setImageResource(id);        

someLinearLayout.addView(temp);    
someLinearLayout.addView(imageView);    
于 2012-05-12T12:18:44.657 回答