繁体   English   中英

将imageView固定在屏幕的左侧,而不是右侧。 XML,Android

[英]Fix an imageView in the left side of the screen but not in the right side. xml, android

在我的android应用程序的第一个视图中,我想在视图顶部显示边框图像。

我想知道如何将图像设置为仅在.xml的左侧固定吗? 由于图片太长,因此不应将其固定在右侧,当您在具有大屏幕的平板电脑上运行该应用程序时,将会从右侧显示更多图片。

这可能吗?

这是我的代码,现在是imageView2我想使用的代码:

<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:background="@drawable/bakgrundsbild"
    tools:context=".FirstView" >

    <ImageView android:id="@+id/imageView1"
               android:layout_height="wrap_content"
               android:layout_width="wrap_content"
               android:layout_centerHorizontal="true"
               android_layout_gravity= "center"
               android:layout_marginLeft="30dp"
               android:layout_marginRight="30dp"
               android:src="@drawable/icon_bakgrund_android">
    </ImageView>


    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/icon_med_logga"
            android:id="@+id/imageView2"
            android:layout_alignParentLeft="true" android:layout_alignTop="@+id/imageView1"/>
    <Button
        android:id="@+id/button1"
        android:layout_width="280dp"
        android:layout_height="50dp"
        android:text="@string/manadens_sollefteblad"
        android:background="@drawable/nybutton"
        android:layout_alignLeft="@+id/button3" android:layout_alignParentTop="true" android:layout_marginTop="473dp"/>

        <Button
        android:id="@+id/button2"
        android:layout_width="280dp"
        android:layout_height="50dp"
        android:text="@string/rabattkuponger"
        android:background="@drawable/nybutton"
        android:layout_alignLeft="@+id/button1" android:layout_alignParentTop="true" android:layout_marginTop="408dp"/>

        <Button
        android:id="@+id/button3"
        android:layout_width="280dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/sa_fungerar_det"
        android:background="@drawable/nybutton" />

        <Button
        android:id="@+id/button4"
        android:layout_width="280dp"
        android:layout_height="50dp"
        android:text="@string/uppdatera"
        android:background="@drawable/nybutton"
        android:layout_alignLeft="@+id/button1" android:layout_alignParentTop="true" android:layout_marginTop="537dp"/>



</RelativeLayout>

您需要使用LinearLayout并为imageview的宽度设置权重 ,以使其不占用屏幕的整个空间。

// try this
<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".FirstView" >

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="left">
            <ImageView android:id="@+id/imageView1"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/ic_launcher">
            </ImageView>
        </LinearLayout>
        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="right">
            <ImageView android:id="@+id/imageView2"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/ic_launcher">
            </ImageView>
        </LinearLayout>
    </LinearLayout>


    <LinearLayout
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:layout_marginTop="20dp"
        android:gravity="center_horizontal"
        android:layout_width="match_parent">

        <LinearLayout
            android:layout_height="0dp"
            android:layout_width="wrap_content"
            android:layout_weight="1">
            <Button
                android:id="@+id/button1"
                android:layout_width="280dp"
                android:layout_height="50dp"
                android:text="manadens_sollefteblad"/>
        </LinearLayout>
        <LinearLayout
            android:layout_height="0dp"
            android:layout_width="wrap_content"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_weight="3">
            <Button
                android:id="@+id/button2"
                android:layout_width="280dp"
                android:layout_height="50dp"
                android:text="rabattkuponger"/>

            <Button
                android:id="@+id/button3"
                android:layout_width="280dp"
                android:layout_height="50dp"
                android:text="sa_fungerar_det"/>
        </LinearLayout>
        <LinearLayout
            android:layout_height="0dp"
            android:layout_width="wrap_content"
            android:layout_weight="1">
            <Button
                android:id="@+id/button4"
                android:layout_width="280dp"
                android:layout_height="50dp"
                android:text="uppdatera"/>
        </LinearLayout>
    </LinearLayout>


</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM