[英]Java/Android: Continuously rotate ImageView image on tap of left/right side of screen
[英]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.