簡體   English   中英

Android ImageView setLayoutParams的寬度大於屏幕的寬度

[英]Android ImageView setLayoutParams with width bigger than Screen

我在這樣的布局xml中有ImageView:

<ImageView
        android:id="@+id/notePointerImageView"
        android:layout_width="700px"
        android:layout_height="6px"
        android:scaleType="fitXY"
        android:src="@drawable/whiteline"

        />

我在onWindowFocusChanged中動態設置寬度,高度和邊距:

RelativeLayout.LayoutParams notePointerLayoutLP = new RelativeLayout.LayoutParams(263, 2); 
        notePointerLayoutLP.setMargins(0, 150, 14, 0);
        notePointerImageView.setLayoutParams(notePointerLayoutLP);
        notePointerImageView.requestLayout();

由於屏幕寬度僅為240x301,因此imageView的左側部分不在屏幕上。 但是看起來好像消除了imageView的那一部分,並且在屏幕內調整了圖像的大小(我使用fitXY),並且使ImageView的大小為226x2。 (226 + 14 == 240,這是屏幕寬度)

由於以后我必須為ImageView設置動畫,因此我不能接受ImageView的裁剪和調整大小。 我真的需要負的左邊距。 有人可以告訴我該怎么做嗎? 還是僅僅是模擬器問題?

要強制大圖像適合屏幕內或某個尺寸,可以將FrameLayout用作:

<FrameLayout
    android:id="@+id/fm_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

       ... ...
>

    <ImageView
        android:id="@+id/myImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:layout_gravity="center"
        android:gravity="center"

        android:src="@drawable/my_image"/>

</FrameLayout>

對於適合的特定大小,您只需設置FrameLayout的布局大小即可。

希望對您有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM