我的活动基于垂直LinearLayout
类似的东西:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="@+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="@layout/title_bar_fragment" />
<ImageView
android:background="@drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="@style/MyTextViewLabel"
android:text="@string/str_under_logo" />
<TextView android:id="@+id/tv_applicationVersion"
style="@style/MyTextViewLabel.Black.Data"
android:textColor="@color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="@style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@color/blue_end"
android:padding="5dp">
<TextView style="@style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="@color/white"/>
<TextView android:id="@+id/tv_serial_number"
style="@style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="@+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="@color/transparent"
android:textColor="@color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
我想将图片作为背景放置,但需要进入右下角。我该怎么做?
编辑:
我尝试这样做,通过包裹FrameLayout
并为图像设置重力,但它不会将图像放到底部,我仍然需要知道如何将它对齐到右边
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_background"
android:layout_gravity="bottom"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="@+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="@layout/title_bar_fragment" />
<ImageView
android:background="@drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="@style/MyTextViewLabel"
android:text="@string/str_under_logo" />
<TextView android:id="@+id/tv_applicationVersion"
style="@style/MyTextViewLabel.Black.Data"
android:textColor="@color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="@style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@color/blue_end"
android:padding="5dp">
<TextView style="@style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="@color/white"/>
<TextView android:id="@+id/tv_serial_number"
style="@style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="@+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="@color/transparent"
android:textColor="@color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
答案 0 :(得分:0)
我建议你把它包装成RelativeLayout
。
然后在ImageView
标记中添加android:layout_alignParentBottom="true"
和android:layout_alignParentRight="true"
,将其对齐在右下角。
<?xml version="1.0" encoding="utf-8"?>
<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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_background"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="@+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="@layout/title_bar_fragment" />
<ImageView
android:background="@drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="@style/MyTextViewLabel"
android:text="@string/str_under_logo" />
<TextView android:id="@+id/tv_applicationVersion"
style="@style/MyTextViewLabel.Black.Data"
android:textColor="@color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="@style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@color/blue_end"
android:padding="5dp">
<TextView style="@style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="@color/white"/>
<TextView android:id="@+id/tv_serial_number"
style="@style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="@+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="@color/transparent"
android:textColor="@color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>