0

カスタムアダプタを使用してギャラリーを作成しています(ウィッチの相対レイアウトでは、画像ビューをサムネイルとして、テキストビューを名前およびその他のスタッフとして配置します)。

ギャラリーはフルスクリーンで完全に表示されますが、これは私が望むものではありません。カスタム相対レイアウトを画面サイズに対して高さと幅を50%に拡大縮小したいと思います。私はこれを試しました:

gallery.getLayoutParams().width = relativelayout.getWidth() / 2;
gallery.getLayoutParams().height = relativelayout.getHeight() / 2;

これは間違った試みでした。コンテンツを拡大縮小せずに、高さと幅を正しいサイズに設定しただけです。

これは元のビューです:

オリジナル

これは私が期待していたことです:

期待

そして、これは私が持っているものです:

結果

これはレイアウトカバーです:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/ivTourCover"
        android:layout_width="640dp"
        android:layout_height="240dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY"
        android:src="@drawable/croppedstopgallery_f45d88e4_7864_4dbc_9123_ad7953d8724a" />

    <ImageButton
        android:id="@+id/ivHorizontalLine"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/tvTourName"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="0dp"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY"
        android:src="@drawable/horizontal_line" />

    <TextView
        android:id="@+id/tvAuthorName"
        style="@style/Cover.AuthorName"
        android:layout_width="fill_parent"
        android:layout_height="19dp"
        android:layout_alignTop="@+id/ivAuthorThumbnail"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="17dp"
        android:layout_toLeftOf="@+id/ivGo"
        android:layout_toRightOf="@+id/ivAuthorThumbnail"
        android:text="Anna Greenleaf" />

    <ImageView
        android:id="@+id/ivAuthorThumbnail"
        android:layout_width="46dp"
        android:layout_height="46dp"
        android:layout_alignLeft="@+id/ivHorizontalLine"
        android:layout_below="@+id/ivHorizontalLine"
        android:layout_marginTop="20dp"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY"
        android:src="@drawable/croppedstopgallery_f45d88e4_7864_4dbc_9123_ad7953d8724a" />

    <ImageView
        android:id="@+id/ivGo"
        android:layout_width="46dp"
        android:layout_height="46dp"
        android:layout_alignRight="@+id/ivHorizontalLine"
        android:layout_alignTop="@+id/tvAuthorName"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY"
        android:src="@drawable/tour_cover_go" />

    <TextView
        android:id="@+id/tvAuthorDescription"
        style="@style/Cover.AuthorDescription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tvAuthorName"
        android:layout_alignRight="@+id/tvAuthorName"
        android:layout_below="@+id/tvAuthorName"
        android:text="London native and London over!" />

    <SurfaceView
        android:id="@+id/svFooter"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="@color/CoverFooter" />

    <TextView
        android:id="@+id/tvFooterText"
        style="@style/Cover.FooterText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/svFooter"
        android:layout_alignBottom="@+id/svFooter"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        android:text="Individual" />

    <com.example.zipdownload.utilities.ui.AutoResizeTextView
        android:id="@+id/tvTourName"
        style="@style/Cover.TourName"
        android:layout_width="wrap_content"
        android:layout_height="79dp"
        android:layout_below="@+id/ivTourCover"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="15dp"
        android:gravity="center|top"
        android:text="Beautiful London in Winston Churchill&apos;s footsteps" />

</RelativeLayout>

ビューギャラリー:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rlGallery"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Gallery" >

    <Gallery
        android:id="@+id/gCoverflow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="top" />

</RelativeLayout>

そしてアクティビティギャラリー:

public class Gallery extends Activity {
    private android.widget.Gallery gCoverflow;
    private RelativeLayout rlGallery;
    private CoverAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gallery);
        rlGallery = (RelativeLayout) findViewById(R.id.rlGallery);
        adapter = new CoverAdapter(this);
        gCoverflow = (android.widget.Gallery) findViewById(R.id.gCoverflow);
        gCoverflow.setAdapter(adapter);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        gCoverflow.getLayoutParams().width = rlGallery.getWidth() / 2;
        gCoverflow.getLayoutParams().height = rlGallery.getHeight() / 2;
    }
}
4

2 に答える 2

1

使用してみることができますScaleAnimationが、この場合、タッチイベントは正しく機能しません。

final ScaleAnimation animation = new ScaleAnimation (
        1f, 0.5f, 1f, 0.5f,
        Animation.RELATIVE_TO_SELF, 0.5f,
        Animation.RELATIVE_TO_SELF, 0.5f
);

final LayoutAnimationController controller = new LayoutAnimationController(animation);

animation.setDuration(0);
animation.setFillAfter(true);

gCoverflow.setLayoutAnimation(controller);

このコードはonCreateメソッドに追加する必要があります。

于 2013-01-07T15:44:58.233 に答える
0

私はそれをみんな見つけました、代わりに:

gCoverflow.getLayoutParams().width = rlGallery.getWidth() / 2;
gCoverflow.getLayoutParams().height = rlGallery.getHeight() / 2;

私はこれを使用します:

gCoverflow.setScaleX((float) 0.5);
gCoverflow.setScaleY((float) 0.5);
于 2013-01-07T15:23:20.103 に答える