Horizo​​ntalScrollView不会滚动

时间:2013-01-10 04:47:14

标签: android-layout

我遇到Horizo​​ntalScrollView的问题,我已将子布局(LinearLayout)设置为2000dp,但仍然不会滚动。我以编程方式设置内容。

这是我的活动布局

<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"
    tools:context=".AktifitasUtama" >
    <HorizontalScrollView
        android:id="@+id/scroll_album_holder"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_margin="5dp"
        android:fillViewport="true">
        <LinearLayout
            android:id="@+id/album_holder"
            android:layout_width="2000dp"
            android:layout_height="wrap_content"
            android:orientation="horizontal"></LinearLayout>
    </HorizontalScrollView>
    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/thumbnail_holder"
        android:numColumns="auto_fit"
        android:gravity="center"
        android:columnWidth="180dp"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</RelativeLayout>

这是我的适配器布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dp" > 
    <ImageView
        android:id="@+id/grid_item_image"
        android:layout_width="fill_parent"
        android:layout_height="160dp"
        android:layout_marginRight="160dp" >
    </ImageView> 
    <TextView
        android:id="@+id/grid_item_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:layout_marginTop="5dp"
        android:textSize="15sp" 
        android:layout_below="@id/grid_item_image"
        android:layout_centerHorizontal="true">
    </TextView> 
</RelativeLayout>

这是我的Activity类

public class AktifitasUtama extends SherlockActivity {

    Session session;
    HorizontalScrollView scroll_album_holder;
    LinearLayout album_holder;
    List<String> album_label = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aktifitas_utama);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            Drawable ab = getResources().getDrawable(R.drawable.header);
            getSupportActionBar().setBackgroundDrawable(ab);
        }
        setSupportProgressBarIndeterminateVisibility(true);
        getSupportActionBar().setHomeButtonEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        session = new Session(getApplicationContext());
        scroll_album_holder = (HorizontalScrollView) findViewById(R.id.scroll_album_holder);
        album_holder = (LinearLayout) findViewById(R.id.album_holder);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.aktifitas_utama, menu);
        return (super.onCreateOptionsMenu(menu));
    }

    @Override
    protected void onResume(){
        super.onResume();
        scroll_album_holder.setVisibility(View.GONE);
        if(session.is_login()){
            fill_album();
        } else {
            startActivity(new Intent(getApplicationContext(), AktifitasMasuk.class));
            finish();
        }
    }

    public void fill_album(){
        album_label.clear();
        int i = 2;
        if(i==1){
            album_label.add("Photo From Camera");
        } else if (i==2){
            album_label.add("Photo From Camera");
            album_label.add("Album 1");
            album_label.add("Album 2");
            album_label.add("Album 3");
            album_label.add("Album 4");
            album_label.add("Album 5");
            album_label.add("Album 6");
        } else if(i==3) {
            album_label.add("Album 1");
            album_label.add("Album 2");
            album_label.add("Album 3"); 
            album_label.add("Album 4");
            album_label.add("Album 5");
            album_label.add("Album 6");     
        }
        if(!album_label.isEmpty()){
            scroll_album_holder.setVisibility(View.VISIBLE);
            for(int j=0;j<album_label.size();j++){
                album_holder.addView(set_album(album_label.get(j)));
            }
        }
    }

    private View set_album(String label){
        LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View album = inflater.inflate(R.layout.grid, null, false);
        ImageView grid_item_image = (ImageView) album.findViewById(R.id.grid_item_image);
        TextView grid_item_label = (TextView) album.findViewById(R.id.grid_item_label);
        Drawable grid_image = getResources().getDrawable(R.drawable.custom_menu_archive);
        grid_item_image.setImageDrawable(grid_image);
        grid_item_label.setText(label);
        return album;
    }

}

那么,您怎么看?有什么建议吗?

0 个答案:

没有答案