是否有任何方法可以将每个图片下方的文本居中?我已经对作品进行了硬编码,但正如您所看到的,长度可能会有所不同!我使用的是相对布局,textView是在每张图片的下方?
0
A
回答
0
<?xml version="1.0" encoding="utf-8"?>
<ImageView android:id="@+id/imgLecture" android:src="@drawable/icon3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_alignParentLeft="true" android:layout_marginTop="30dp" android:layout_marginLeft="60dp"></ImageView>
<ImageView android:id="@+id/imgMail" android:src="@drawable/icon4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_alignParentRight="true" android:layout_marginTop="30dp" android:layout_marginRight="60dp"></ImageView>
<TextView android:text="Lectures" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:layout_below="@+id/imgLecture" android:layout_alignParentLeft="true" android:layout_marginLeft="60dp" android:layout_marginTop="2dp" ></TextView>
<TextView android:text="Mail" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:layout_below="@+id/imgMail" android:layout_alignParentRight="true" android:layout_marginRight="60dp" android:layout_marginTop="2dp" ></TextView>
<ImageView android:id="@+id/imgExam" android:src="@drawable/icon5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView3" android:layout_alignParentLeft="true" android:layout_marginTop="30dp" android:layout_marginLeft="60dp"></ImageView>
<ImageView android:id="@+id/imgGrade" android:src="@drawable/icon6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView4" android:layout_alignParentRight="true" android:layout_marginTop="30dp" android:layout_marginRight="60dp"></ImageView>
<TextView android:text="Exams" android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:layout_below="@+id/imgExam" android:layout_alignParentLeft="true" android:layout_marginLeft="60dp" android:layout_marginTop="2dp" ></TextView>
<TextView android:text="Grades" android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:layout_below="@+id/imgGrade" android:layout_alignParentRight="true" android:layout_marginRight="60dp" android:layout_marginTop="2dp" ></TextView>
1
使用线性布局的组合,你可以做到这样的事情
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" android:gravity="center_vertical">
<LinearLayout android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.0" android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test" android:gravity="center"/>
</LinearLayout>
<LinearLayout android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1.0"
android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test" android:gravity="center"/>
</LinearLayout>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" android:gravity="center_vertical">
<LinearLayout android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.0" android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test" android:gravity="center"/>
</LinearLayout>
<LinearLayout android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1.0"
android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test" android:gravity="center"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
但我强烈建议查看我发送的评论文章。它使用仪表板布局。
+0
+1正确!链接也很有用,在书签中添加。 – MKJParekh
0
这是很难通过您的XML文件... 为什么你不使用gridview和每个视图,你可以有一个图像下面的文本...这很容易这种方式...
相关问题
- 1. 如何将RelativeLayout对齐中心android
- 2. RelativeLayout,对齐左/右两个按钮,对齐中心为一个
- 3. Android的 - 对齐中心的RelativeLayout中的FrameLayout
- 4. 如何将RelativeLayout中的按钮设置为与中心对齐
- 5. 表对齐中心不对齐中心
- 6. 在RelativeLayout中对齐组件
- 7. Android在顶部和中心在RelativeLayout中对齐图像
- 8. RelativeLayout,如何对齐其他视图的中心?
- 9. 将顶部imageView与一个relativeLayout的中心对齐
- 10. 在FrameLayout中将RelativeLayout中的TextView对齐
- 11. 获取屏幕的中心线并根据它对齐视图
- 12. Android中的中心对齐
- 13. RelativeLayout中的按钮对齐不正确
- 14. JavaScript中心对齐
- 15. 对齐中心div
- 16. CSS - 对齐中心
- 17. 对齐中心Javascript
- 18. 中心对齐表
- 19. 如何根据图像将文本对齐到中心
- 20. 在我的应用程序中将TextView对齐到RelativeLayout的中心
- 21. 对齐TextViews与RelativeLayout的
- 22. 对齐中心对齐div元素
- 23. 中心对齐/ bash中
- 24. 在Flex中对齐中心
- 25. 中心的文本对齐
- 26. 中心对齐的DIV
- 27. 中心对齐的div
- 28. 在TOP-CENTER中与RelativeLayout对齐
- 29. 在RelativeLayout中正确对齐TextViews
- 30. 在RelativeLayout中对齐两个TextView
看看这个http://www.samcoles.co.uk/mobile/android-implementing-a-dashboard-activity/ – blessenm
你可以发布xml代码吗? –