0

私はこの質問が至る所で尋ねられるのを見ました、しかし私はそれぞれの場合がそれ自身の解決策を持っていると思います。私が持っているのはこれです:

<HorizontalScrollView
    android:id="@+id/MenuScroll"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="none" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:orientation="horizontal"
            android:layout_gravity="center"
        android:padding="0dp" >

        <Button
            android:layout_width="150dp"
            android:layout_height="fill_parent" />

        <Button
            android:layout_width="150dp"
            android:layout_height="fill_parent" />

        <Button
            android:layout_width="150dp"
            android:layout_height="fill_parent" />

        <Button
            android:layout_width="150dp"
            android:layout_height="fill_parent" />

        <Button
            android:layout_width="150dp"
            android:layout_height="fill_parent" />

    </LinearLayout>
</HorizontalScrollView>

そして、私がふりをしているのは、のLinearLayout中央に配置されていることHorizontalScrollViewです。中央に配置されていますが(halfbutton-button-halfbuttonが表示されます)、最初のボタンまでスクロールできません。左側に隠されているコンテンツが占めるスペースが右側に追加され、の後にスペースが追加されているように見えHorizontalScrollViewます。 ここに画像の説明を入力してください

動的に実行する必要がある場合でも、解決策はありますか?

4

1 に答える 1

1

私はこれと同じ問題を抱えていました、それを避けるためにただ削除する

 android:layout_gravity="center"

から

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:orientation="horizontal"
        android:layout_gravity="center"
    android:padding="0dp" >

レイアウトビューの作成中にタイマーを追加して、適切にスクロールすることができます。タイマーを追加しないと、ビューが作成されていないため、タイマーはスクロールしません。まだ見えないものはスクロールできません

 new Timer().schedule(new TimerTask () {
        @Override
        public void run() {
            //SOME SCROLLING FUNCTION
            }}, 50);        
于 2013-03-04T20:38:53.403 に答える