English 中文(简体)
Android, 如何在屏幕中间 带来选中的自定义视图?
原标题:Android, How to bring selected custom view in the middle of screen?

""https://i.sstatic.net/uQprG.png" alt="此处输入图像描述"/ >


Hi,
As you can see in above image, I created a custom view as as item of my calendar. In code i have repeat it for example 50 times to create calendar.

服务器给我发送一个旗帜, 显示其中哪个应该选中( 在此情况下, 选择了 09 Jun ) 。

我的问题是当服务器发送一个不在屏幕上的一天( 例如 25 Jun) 时, 日期会被选中( 25 Jun 更改的背景), 但是在屏幕上我可以看到图像( 但现在 9 Jun 的背景已变换为白色 ) 。

我要找的就是在屏幕中间显示 6月25日的项目。我不知道它是如何可能的。

请提出任何建议。 Mu 习惯观点(widget)的代码是这样的:

public class Calendar_Item extends RelativeLayout {

    private LayoutInflater mInflater;
    private RelativeLayout rlContainer;
    private TextView tvMonth;
    private TextView tvDay;
    private ImageView imDot;

    public Calendar_Item(Context context) {
        super(context);
        init(context);
    }

    public Calendar_Item(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public Calendar_Item(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }


    private void init(Context context) {
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        RelativeLayout calendarView = (RelativeLayout) mInflater.inflate(R.layout.calendar_item, null);
        addView(calendarView);

        rlContainer = (RelativeLayout)  calendarView.findViewById(R.id.cal_rlContainer);
        tvMonth     = (TextView)        calendarView.findViewById(R.id.cal_month);
        tvDay       = (TextView)        calendarView.findViewById(R.id.cal_date);
        imDot       = (ImageView)       calendarView.findViewById(R.id.cal_dot);
    }



    public void setMonth(String month) {
        tvMonth.setText(month);
    }

    public void setMonth(int resId) {
        tvMonth.setText(resId);
    }

    public CharSequence getMonth() {
        return tvMonth.getText();
    }

    public void setDay(String day) {
        tvDay.setText(day);
    }

    public void setDay(int resId) {
        tvDay.setText(resId);
    }

    public CharSequence getDay() {
        return tvDay.getText();
    }

    public void showDot() {
        imDot.setVisibility(View.VISIBLE);
    }

    public void hideDot() {
        imDot.setVisibility(View.INVISIBLE);
    }

    public void setTextColor(int color) {
        tvDay.setTextColor(color);
    }

    public void setBackgroundResource(int resid) {
        rlContainer.setBackgroundResource(resid);
    }

    public void setBackgroundDrawable(Drawable d) {
        rlContainer.setBackgroundDrawable(d);
    }

    public void setBackgroundColor(int color) {
        rlContainer.setBackgroundColor(color);
    }
}

XML 代码布局 :

    <?xml version="1.0" encoding="utf-8"?>

<HorizontalScrollView 
   xmlns:android            = "http://schemas.android.com/apk/res/android"
   android:layout_width     = "fill_parent" 
   android:layout_height    = "wrap_content"
   android:layout_below     = "@id/header"
   android:fadingEdgeLength = "30dip"
   android:fadingEdge       = "horizontal"
   android:scrollbars       = "none" >

   <LinearLayout 
        android:id              = "@+id/llCalendarItems"
        android:layout_width    = "wrap_content" 
        android:layout_height   = "wrap_content"
        android:orientation     = "horizontal" >

    </LinearLayout>
</HorizontalScrollView>

所有日历项目都位于LinearLayout内。

问题回答

最后我找到了我使用补缺方法的方法

hsv = (HorizontalScrollView) findViewById(R.id.hsvCalendar);
hsv.postDelayed(new Runnable() {
    public void run() {
    hsv.scrollTo(selectedDay * 100, 0);
}
}, 100L);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签