Hai*_*iro 21 android android-layout
我有一些图像按钮,每个都有相应的文本视图,我想将这些文本视图对齐到相应的图像视图的中心,我的意思是,就像在应用程序抽屉上看到的那样......
!-----!
!icon !
!_____!
app name
Run Code Online (Sandbox Code Playgroud)
这是我的代码,我正在使用 RelativeLayout
<ImageButton
android:id="@+id/blog_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/logo_img"
android:layout_marginLeft="50dp"
android:layout_marginTop="51dp"
android:background="@null"
android:contentDescription="@string/blog_desc"
android:src="@drawable/blog" />
<TextView
android:id="@+id/blog_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/blog_button"
android:layout_below="@+id/blog_button"
android:layout_marginTop="8dp"
android:text="@string/blog_desc" />
Run Code Online (Sandbox Code Playgroud)
Jas*_*son 32
将LinearLayout孩子包裹在孩子的中心,如下:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/logo_img"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageButton
android:id="@+id/blog_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:contentDescription="@string/blog_desc"
android:src="@drawable/blog" />
<TextView
android:id="@+id/blog_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/blog_desc" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
小智 17
老帖子,但如果这可以帮助我认为没有必要添加额外的容器.
<ImageButton
android:id="@+id/blog_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/logo_img"
android:layout_marginLeft="50dp"
android:layout_marginTop="51dp"
android:background="@null"
android:contentDescription="@string/blog_desc"
android:src="@drawable/blog" />
<TextView
android:id="@+id/blog_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/blog_button"
android:layout_alignRight="@+id/blog_button"
android:layout_below="@+id/blog_button"
android:gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_marginLeft="-20dp"
android:layout_marginRight="-20dp"
android:text="@string/blog_desc" />
Run Code Online (Sandbox Code Playgroud)
这对我有用.
| 归档时间: |
|
| 查看次数: |
28220 次 |
| 最近记录: |