1d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang/*
2d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * Copyright (C) 2011 The Android Open Source Project
3d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang *
4d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * Licensed under the Apache License, Version 2.0 (the "License");
5d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * you may not use this file except in compliance with the License.
6d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * You may obtain a copy of the License at
7d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang *
8d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang *      http://www.apache.org/licenses/LICENSE-2.0
9d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang *
10d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * Unless required by applicable law or agreed to in writing, software
11d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * distributed under the License is distributed on an "AS IS" BASIS,
12d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * See the License for the specific language governing permissions and
14d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang * limitations under the License.
15d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang */
16d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang
17d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wangpackage com.android.camera.ui;
18d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang
19d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wangimport android.content.Context;
20d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wangimport android.view.View;
21d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wangimport android.util.AttributeSet;
22d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wangimport android.widget.HorizontalScrollView;
23d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang
24d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wangpublic class RightAlignedHorizontalScrollView extends HorizontalScrollView {
25d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang
26d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang    public RightAlignedHorizontalScrollView(Context context) {
27d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang        super(context);
28d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang    }
29d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang
30d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang    public RightAlignedHorizontalScrollView(Context context, AttributeSet attrs) {
31d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang        super(context, attrs);
32d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang    }
33d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang
34d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang    @Override
35d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang    protected void onLayout(boolean changed, int l, int t, int r, int b) {
36d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang        super.onLayout(changed, l, t, r, b);
37d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang        if (changed) {
38d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang            // Get the width of the child, i.e. the LinearLayout, and scroll to
39d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang            // the rightmost position.
40d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang            View child = getChildAt(0);
41d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang            if (child != null) scrollTo(child.getWidth(), 0);
42d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang        }
43d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang   }
44d33109730e0ab81230f84e2bd35599e8e24fc4baChung-yih Wang}
45