eri*_*lee 10 android android-layout
我有这个问题的textview不在图像按钮下面居中.无论如何要解决这个问题?编码和图像在下面给出!
<LinearLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp">
<RelativeLayout android:gravity="center" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/nopic" >
</ImageButton>
<TextView
style="@style/MenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
<RelativeLayout android:gravity="center" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnContact"
android:src="@drawable/nopic" >
</ImageButton>
<TextView
style="@style/MenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
</LinearLayout>
<LinearLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp">
<RelativeLayout android:gravity="center" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnRoute"
android:src="@drawable/nopic" >
</ImageButton>
<TextView
style="@style/MenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
<RelativeLayout android:gravity="center" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnChecList"
android:src="@drawable/nopic" >
</ImageButton>
<TextView
style="@style/MenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Ven*_*nky 16
试试这个片段:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center_vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/ic_launcher" >
</ImageButton>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/ic_launcher" >
</ImageButton>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/ic_launcher" >
</ImageButton>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Mas*_*imo 10
你可以做,简单地说(!!!):
android:layout_alignRight="@id/my_image_view"
android:layout_alignLeft="@id/my_image_view"
Run Code Online (Sandbox Code Playgroud)
只需将它左右对齐,结果是TextView居中.