小编Aus*_*ers的帖子

Android布局宽度为50%

我使用相对布局来创建XML的Android UI.布局以ImageView和TextView为中心.我需要将这两个元素放在彼此的上方和下方.我想这样做,这两个元素占整个宽度的50%.我尝试了一个LinearLayout android:layout_weight=".5"但是我无法让它在水平和垂直方向都居中.这是我的相对布局,我希望它看起来像这样但是图像占据了宽度的50%,两边都有25%的空白.我还需要用XML来做.任何指导表示赞赏.

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/activity_main_imageview_logo"
        android:src="@drawable/img_main_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop"
        android:paddingBottom="12dp"
        android:onClick="imageViewGTTOnClick"
        android:adjustViewBounds="true" />
    <TextView
        android:id="@+id/activity_main_textview_tagline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/activity_main_textview_tagline"
        android:textColor="@color/dark_blue"
        android:gravity="center"
        android:textSize="28sp"
        android:layout_below="@+id/activity_main_imageview_logo"
        android:layout_centerHorizontal="true" />

 </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

xml android android-layout

3
推荐指数
1
解决办法
1898
查看次数

标签 统计

android ×1

android-layout ×1

xml ×1