0

In the first View of my android application I want to have a image of a border in the top of the view.

I wonder how I can set the image to be fixed only in the left side in my .xml? It should not be fixed in the right side because the picture is long and when you run the app on a tablet with a big screen more of the picture will show from the right side.

Is this possible?

Here is my code for now and it is the imageView2 that I want to do this with:

<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>
4

2 回答 2

0

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

于 2013-10-23T09:44:40.830 回答
0
// 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>
于 2013-10-23T09:59:03.707 回答