0

異なる相対レイアウトとビューのレイヤーを含む相対レイアウトがあります。1 つの子相対レイアウトに、サイズが 2400*480、1600*480、920*480 の画像を追加しました。これらの画像は元のサイズを維持したいのですが、相対レイアウトに追加すると画面の幅と高さに合わせて縮小され、縮小されたときにアスペクト比も維持されます。以下は、ImageViews を追加するための XML とコードです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
        /* Some other layouts */
    <RelativeLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content"                      
        android:id="@+id/parallaxLayers"        
        android:visibility="gone">      
    </RelativeLayout>
    /* Viewgroup */    
</RelativeLayout>

RelativeLayout parallaxLayout = (RelativeLayout)findViewById(R.id.parallaxLayers);

private void addParallaxLayers() {
        // TODO Auto-generated method stub
        InputStream s1 = getResources().openRawResource(R.drawable.parallax_layer1);
        InputStream s2 = getResources().openRawResource(R.drawable.parallax_layer2);
        InputStream s3 = getResources().openRawResource(R.drawable.parallax_layer3);
        InputStream s4 = getResources().openRawResource(R.drawable.parallax_layer4);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        System.gc();
        bitmap = bitmap(s1);
        layer1Back = new ImageView(this);       
        layer1Back.setImageBitmap(bitmap);
        parallaxLayout.addView(layer1Back, 0, lp);
        try {
            s1.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        bitmap = null;
        s1 = null;
        System.gc();

        bitmap = bitmap(s2);
        layer2Back = new ImageView(this);
        layer2Back.setImageBitmap(bitmap);
        parallaxLayout.addView(layer2Back, 1, lp);
        try {
            s2.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        bitmap = null;
        s2 = null;
        System.gc();

        bitmap = bitmap(s3);
        layer3Back = new ImageView(this);
        layer3Back.setImageBitmap(bitmap);
        parallaxLayout.addView(layer3Back, 2, lp);
        try {
            s3.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        bitmap = null;
        s3 = null;
        System.gc();

        bitmap = bitmap(s4);
        layer4Back = new ImageView(this);
        layer4Back.setImageBitmap(bitmap);
        parallaxLayout.addView(layer4Back, 3, lp);
        try {
            s4.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        bitmap = null;
        s4 = null;
        System.gc();
    }

相対レイアウトのサイズを変更する必要がある場合でも、これらの画像を元のサイズに合わせるにはどうすればよいですか?

4

3 に答える 3

0

結局、framelayoutを備えたHorizo​​ntalScrollViewを使用して、imageviewを相互に配置しました。

<HorizontalScrollView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fadingEdge="none">
            <FrameLayout android:layout_width="wrap_content"
                android:layout_height="fill_parent"                   
                android:id="@+id/parallaxLayers"        
                android:visibility="gone">      
            </FrameLayout>
        </HorizontalScrollView>
于 2012-04-24T08:09:13.483 に答える
0

ImageView ごとに次の行を試してください。

 layer2Back.setScaleType(ScaleType.FIT_XY);

私はわかりません。

于 2012-04-18T09:24:34.613 に答える
0

私はそのようなものだと思います:

layer2Back.setScaleType(ScaleType.FIT_CENTER);
于 2012-04-18T09:27:09.853 に答える