【发布时间】:2016-10-14 16:17:25
【问题描述】:
我需要在屏幕顶部放置 5 个imageButtons。我是这样用LinarLayout 做到的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.terrormachine.swipeapp.NewAdFragment">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/image"
android:id="@+id/imageButton6"
android:layout_weight="1"
android:scaleType="fitCenter" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/image"
android:id="@+id/imageButton7"
android:layout_weight="1"
android:scaleType="fitCenter" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/image"
android:id="@+id/imageButton8"
android:layout_weight="1"
android:scaleType="fitCenter" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/image"
android:id="@+id/imageButton9"
android:layout_weight="1"
android:scaleType="fitCenter" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/image"
android:id="@+id/imageButton10"
android:layout_weight="1"
android:scaleType="fitCenter" />
</LinearLayout>
</RelativeLayout>
问题是我需要在每张图片下方居中放置文本。我尝试了几种解决方案,但似乎没有一个对我有用。 我试过这个:
Android Text Below Icon (button) How to add a text under the image button in Android? How to place text below a Button or a ImageButton?
其中一些可以解决问题,但图像没有缩放。就我而言,我无法在下面设置文本。有没有办法做到这一点?
我不必使用LinearLayout,但我想不出任何适当的方法来将它们等距放置并具有屏幕宽度。欢迎任何想法。
【问题讨论】: