layout with text surrounding a button
could some one suggest me how to implement the layout like fo开发者_如何转开发llowing:
That's multiple lines of texts surrounding a button. Probably a linear layout?
You have to create two linear layouts
inner layout with horizontal orientation ( which will one textview and one button)
outer layout with verticalr orientation which wil have textview with wrap content
Similar to the following
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Cache"/>
</LinearLayout>
<TextView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
You can use a RelativeLayout and then the you can format the layout with the command
android:layout_above="@+id/mybutton"
android:layout_below="@+id/mybutton"
android:layout_toRightOf="@+id/mybutton"
android:layout_toLeftOf="@+id/mybutton"
See more infos to RelativeLayout at the API-Site (http://developer.android.com/reference/android/widget/RelativeLayout.html)
So have only one Layout with 5 componentes (4 TextFileds and the Button)
EDIT:
here is a quick and dirty solution - but it worked fine for me
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/my_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="BUTTON"
android:layout_centerInParent="true"
/>
<TextView
android:id="@+id/text_above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/my_button"
android:text="TEXT ABOVE BUTTON"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/text_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/my_button"
android:text="TEXT LEFT OF BUTTON"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/text_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/my_button"
android:text="TEXT RIGHT OF BUTTON"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/text_BELOW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/my_button"
android:text="TEXT BELOW BUTTON"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
精彩评论