我试图将图像按钮的位置设置在中心,但它不起作用。
现在,当我尝试将其设置为中心时,它几乎向右移动。
有人可以告诉我我的代码中出错的地方吗?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#EBEBEB" >
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#EBEBEB" >
<ImageView
android:id="@+id/imagefield"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="5dp"
android:src="@drawable/imagefield"
android:background="@null"/>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:onClick="imagebutton1"
android:layout_alignBottom="@+id/imagefield"
android:layout_centerHorizontal="true"
/>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imagebutton1"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
答案 0 :(得分:0)
在ImageButton
<ImageButton
...
android:gravity="center"
...
/>
答案 1 :(得分:0)
COPY PASTE BELOW CODE
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#EBEBEB" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#EBEBEB" >
<ImageView
android:id="@+id/imagefield"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="@null"
android:src="@drawable/ic_action_chat" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:onClick="imagebutton1" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imagefield"
android:layout_alignTop="@+id/imagefield"
/>
</RelativeLayout>
</ScrollView>
答案 2 :(得分:0)
如果您想要“...图像按钮位于ImageView的底部,中心”
然后你需要将它们放在FrameLayout中。
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:background="#EBEBEB" >
<ImageView
android:id="@+id/imagefield"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="5dp"
android:src="@drawable/imagefield"
android:background="@null"/>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:onClick="imagebutton1"
android:layout_alignBottom="@+id/imagefield"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal|bottom" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton1"
android:layout_centerHorizontal="true" />
</FrameLayout>
答案 3 :(得分:0)
试试这个:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imagefield"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_menu_home"
android:layout_centerHorizontal="true"
/>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_menu_share"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@id/imagefield"
/>
</RelativeLayout>