开发者

Android ImageButton not aligned with EditText and Button

I currently have this in my layout.xml

        <开发者_如何学PythonEditText android:id="@+id/body" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1"
            android:hint="Type to compose" />
        <ImageButton android:id="@+id/attach"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:src="@drawable/attach_photo" />
        <Button android:id="@+id/send" android:text="@string/send"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </LinearLayout>

Problem I'm facing is the top of the ImageButton is not aligned like the Button and EditText. The other 2 fill up the height nicely but the ImageButton seems to be sticking out upwards. Any ideas?


Try using a RelativeLayout. You can align views to the sides, top and bottom of the parent or any other view.

Using android:layout_alignParentTop="true" or similar.

There are loads of xml commands you can use in RelativeLayout.


You can also set the layout weight property on the children of your linear layout. You can set the weight of edittext, imagebutton and button which will align your components on screen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜