Dim*_*tri 16 android android-imageview
我很难让我的imageview出现在屏幕的一半,有人可以提供帮助.这是我的xml文件.它应该占用屏幕尺寸的一半,并且带有textview的线性布局应该位于imageview的页脚.
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fond" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/relativeLayout1" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true" >
<WebView
android:id="@+id/webcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="151dp" />
</RelativeLayout>
<ImageView
android:id="@+id/image_actualitedetails"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/six_yamaha" />
<LinearLayout
android:id="@+id/linearvideo"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:layout_alignBottom="@+id/image_actualitedetails"
android:layout_alignParentLeft="true"
android:background="#88FFFFFF"
android:gravity="center"
android:paddingLeft="@dimen/fourdp"
android:paddingRight="@dimen/fourdp" >
<TextView
android:id="@+id/text_actualites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="@color/tabDark"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/header" >
<Button
android:id="@+id/boutton_retour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="14dp"
android:background="@drawable/back" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
zTr*_*rix 44
使用LinearyLayout包装ImageView和另一个不可见的View,并将layout_weight设置为0.5,然后ImageView应该是一半大小.
下面是一个示例,显示如何将图像设置为屏幕大小的一半
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="#ff0000"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/your_image"
android:adjustViewBounds="true"
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="#00ff00"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这就是结果

如果您想将图像放在屏幕中央,可以使用相同的想法并设置适当的重量来实现目标.祝好运!