我试图在其 LinearLayout 父级中将 RelativeLayout 居中。
但它一直在左边。
我怎样才能解决这个问题?
顺便说一句,当前只有两者中的一个可见:(刷新/动作线性布局)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/app_widget_root"
android:layout_width="wrap_content"
android:layout_height="90dp"
android:orientation="vertical"
android:padding="0dp"
android:clickable="true"
android:focusable="true"
android:background="@drawable/widget_bg_main"
>
<!-- -->
<RelativeLayout
android:id="@+id/layout_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
>
<!--========================================================================
* Action layout - action buttons container
======================================================================== -->
<LinearLayout
android:id="@+id/layout_action"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_toRightOf="@+id/layout_information"
>
<ImageView android:id="@+id/image_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/widget_bt_drive_disabled"
android:layout_marginTop="25dp"
/>
<TextView
android:id="@+id/text_view_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:layout_marginTop="6dp"
android:textColor="@color/disabled_white"
android:text="Drive!"
/>
</LinearLayout> <!-- Action layout -->
<!--========================================================================
* Refresh layout - refresh layout
======================================================================== -->
<RelativeLayout
android:id="@+id/layout_refresh"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:visibility="invisible"
android:layout_marginTop="5dp"
android:layout_marginLeft="72dp"
>
<!--
android:clickable="true"
android:background="@android:drawable/list_selector_background" -->
<ImageView android:id="@+id/image_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/widget_bt_refresh_idle"
android:layout_gravity="center"
/>
<TextView android:id="@+id/refresh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_marginTop="25dp"
android:layout_marginLeft="35dp"
android:textColor="@color/solid_white"
android:text="Click to refresh"
/>
</RelativeLayout> <!-- refresh notification view -->
</RelativeLayout> <!-- main view -->
</LinearLayout>
更新1
我尝试了以下失败:
<RelativeLayout
android:id="@+id/layout_refresh"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:orientation="horizontal"
android:visibility="invisible"
android:layout_alignLeft="@+id/layout_status_image"
android:layout_marginTop="5dp"
android:layout_marginLeft="72dp"
android:gravity="center"
android:layout_gravity="center"
>
<!--
android:clickable="true"
android:background="@android:drawable/list_selector_background" -->
<ImageView android:id="@+id/image_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/widget_bt_refresh_idle"
android:layout_centerInParent="true"
/>
<TextView android:id="@+id/refresh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_marginTop="25dp"
android:layout_marginLeft="35dp"
android:textColor="@color/solid_white"
android:text="Click to refresh"
/>
我想把图片和文字放在中间
更新 3
XML
android:id="@+id/app_widget_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/widget_bg_main"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:padding="0dp"
android:gravity="center_vertical"
>
<RelativeLayout
android:id="@+id/layout_status_image"
android:layout_width="82dp"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_weight=".2">
<ImageView
android:id="@+id/image_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:src="@drawable/widget_icon_no_data"
android:visibility="invisible" />
<!--
Layout is necessary because the setVisibility of ProgressBar is not working
through remote views in 2.1. So wrapped by this layout
-->
<FrameLayout
android:id="@+android:id/widget_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:layout_centerInParent="true">
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="39dp"
android:layout_height="39dp"
android:indeterminateOnly="true"
android:orientation="vertical" />
</FrameLayout>
</RelativeLayout> <!-- Status image layout -->
<!--
========================================================================
* Information layout - contains all the texts
========================================================================
-->
<LinearLayout
android:id="@+id/layout_information"
android:layout_width="190dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".6"
>
<TextView
android:id="@+id/text_view_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="\@ Home in"
android:textColor="@color/solid_white"
android:textSize="19sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:paddingLeft="9dp"
android:textColor="@color/solid_white"
android:textSize="25sp"
android:textStyle="normal" />
</LinearLayout> <!-- Information layout -->
<!--
========================================================================
* Action layout - action buttons container
========================================================================
-->
<LinearLayout
android:id="@+id/layout_action"
android:layout_width="80dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:layout_weight=".2"
>
<ImageView
android:id="@+id/image_action"
android:layout_width="wrap_content"
android:layout_height="wrap_contenth"
android:src="@drawable/widget_bt_drive_disabled" />
<TextView
android:id="@+id/h"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="Refresh"
android:textColor="@color/disabled_white"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout> <!-- Action layout -->
屏幕:
我已经删除了 relativeLayout,但它Refresh Text
并没有在它的框中居中。
知道为什么吗?