Skip to content

Commit

Permalink
Adapter 翻译完成
Browse files Browse the repository at this point in the history
  • Loading branch information
cnmahj committed Jun 9, 2011
1 parent 6744dbe commit 770a97b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 61 deletions.
23 changes: 9 additions & 14 deletions frameworks/base/core/java/android/view/LayoutInflater.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,16 @@ public View inflate(XmlPullParser parser, ViewGroup root) {
}

/**
* Inflate a new view hierarchy from the specified xml resource. Throws
* {@link InflateException} if there is an error.
* 根据指定的 XML 资源展开新视图树。如果发生错误,抛出{@link InflateException}异常。
*
* @param resource ID for an XML layout resource to load (e.g.,
* <code>R.layout.main_page</code>)
* @param root Optional view to be the parent of the generated hierarchy (if
* <em>attachToRoot</em> is true), or else simply an object that
* provides a set of LayoutParams values for root of the returned
* hierarchy (if <em>attachToRoot</em> is false.)
* @param attachToRoot Whether the inflated hierarchy should be attached to
* the root parameter? If false, root is only used to create the
* correct subclass of LayoutParams for the root view in the XML.
* @return The root View of the inflated hierarchy. If root was supplied and
* attachToRoot is true, this is root; otherwise it is the root of
* the inflated XML file.
* @param resource 要载入的 XML 布局资源ID(例:<code>R.layout.main_page</code>)。
* @param root 可以作为生成的视图树的父视图(如果<em>attachToRoot</em>为真),
* 或者是简单的提供用于视图树根视图的 LayoutParams 值的对象
* (如果<em>attachToRoot</em>为假)。
* @param attachToRoot 是否将展开的视图加入根视图树。如果为假,
* root 仅用于为 XML 中的跟视图提供正确的 LayoutParams 的子类。
* @return 展开的视图树的根视图。如果提供了 root,并且 attachToRoot 为真,则为 root;
* 否则为展开的 XML 文件中的根视图。
*/
public View inflate(int resource, ViewGroup root, boolean attachToRoot) {
if (DEBUG) System.out.println("INFLATING from resource: " + resource);
Expand Down
56 changes: 27 additions & 29 deletions frameworks/base/core/java/android/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -4137,13 +4137,13 @@ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
}

/**
* {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent)
* KeyEvent.Callback.onKeyMultiple()} 的默认实现. 如果视图可用并可按
* 当按下 {@link KeyEvent#KEYCODE_DPAD_CENTER} 或 {@link KeyEvent#KEYCODE_ENTER}
* 时执行视图的按下事件.
* {@link KeyEvent.Callback#onKeyDown(int, KeyEvent)
* KeyEvent.Callback.onKeyDown()} 的默认实现. 如果视图可用并可响应单击事件
* 当释放 {@link KeyEvent#KEYCODE_DPAD_CENTER} 或 {@link KeyEvent#KEYCODE_ENTER}
* 时执行视图的单击事件.
*
* @param keyCode 表示按下的键的、在 {@link KeyEvent#KEYCODE_ENTER} 中定义的键盘代码.
* @param event KeyEvent 对象,定义了按钮动作.
* @param keyCode 代表按钮按下的、在 {@link KeyEvent} 中定义的键盘代码.
* @param event KeyEvent 对象,定义了按键动作.
*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean result = false;
Expand Down Expand Up @@ -4171,21 +4171,20 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
}

/**
* Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent)
* KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle
* the event).
* {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent)
* KeyEvent.Callback.onKeyLongPress()} 的默认实现:总是返回假(不处理事件)。
*/
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
return false;
}

/**
* {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent)
* KeyEvent.Callback.onKeyMultiple()} 的默认实现.
* {@link KeyEvent.Callback#onKeyUp(int, KeyEvent)
* KeyEvent.Callback.onKeyUp()} 的默认实现.
* 当释放 {@link KeyEvent#KEYCODE_DPAD_CENTER} 或 {@link KeyEvent#KEYCODE_ENTER}
* 时执行视图的单击事件.
*
* @param keyCode 表示按下的键的、在 {@link KeyEvent#KEYCODE_ENTER} 中定义的键盘代码.
* @param keyCode 表示按下的键的、在 {@link KeyEvent} 中定义的键盘代码.
* @param event KeyEvent 对象,定义了按钮动作.
*/
public boolean onKeyUp(int keyCode, KeyEvent event) {
Expand Down Expand Up @@ -4217,7 +4216,7 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
* {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent)
* KeyEvent.Callback.onKeyMultiple()} 的默认实现. 不处理该事件,总是返回假.
*
* @param keyCode 表示按下的键的、在 {@link KeyEvent#KEYCODE_ENTER} 中定义的键盘代码.
* @param keyCode 表示按下的键的、在 {@link KeyEvent} 中定义的键盘代码.
* @param repeatCount 按键次数.
* @param event KeyEvent 对象,定义了按钮动作.
*/
Expand All @@ -4226,12 +4225,11 @@ public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
}

/**
* Called when an unhandled key shortcut event occurs.
* 当未处理的键盘快捷键事件发生时调用。
*
* @param keyCode The value in event.getKeyCode().
* @param event Description of the key event.
* @return If you handled the event, return true. If you want to allow the
* event to be handled by the next receiver, return false.
* @param keyCode 由 event.getKeyCode() 取得的键值。
* @param event 键盘事件的描述。
* @return 如果你处理了事件,返回真;如果你允许下一个接收者来处理该事件,返回假。
*/
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
return false;
Expand Down Expand Up @@ -4339,8 +4337,8 @@ protected void onCreateContextMenu(ContextMenu menu) {
/**
* 实现该方法来处理轨迹球动作事件。轨迹球<em>相对</em>于上次移动的位置可以通过
* {@link MotionEvent#getX MotionEvent.getX()} 和
* {@link MotionEvent#getY MotionEvent.getY()} 取得。对应用户按下一次方向键
* 他们通常作为一次移动处理(为了表现来自轨迹球的更小粒度的移动信息,他们返回小数)。
* {@link MotionEvent#getY MotionEvent.getY()} 取得。用户按下一次方向键
* 通常作为一次移动处理(为了表现来自轨迹球的更小粒度的移动信息,他们返回小数)。
*
* @param event 动作事件。
* @return 如果处理了事件,返回真;否则返回假。
Expand Down Expand Up @@ -8192,24 +8190,24 @@ public final void measure(int widthMeasureSpec, int heightMeasureSpec) {

/**
* <p>
* 评估视图及其内容,以决定其宽度和高度.此方法由 {@link #measure(int, int)}
* 调用,子类可以重载以提供更精确、更有效率的衡量其内容尺寸的方法.
* 测量视图及其内容,以决定其宽度和高度此方法由 {@link #measure(int, int)}
* 调用,子类可以重写该方法以提供更精确、更有效率的测量其内容尺寸的方法。
* </p>
*
* <p>
* <strong>约定:</strong> 覆盖该方法时,<em>必须</em>调用 {@link #setMeasuredDimension(int, int)}
* 方法来保存评估结果的视图的宽度和高度.如果忘记将导致 {@link #measure(int, int)}
* 方法抛出<code>IllegalStateException</code>异常.要有效的利用父类的
* {@link #onMeasure(int, int)}方法.
* <strong>约定:</strong> 重写该方法时,<em>必须</em>调用 {@link #setMeasuredDimension(int, int)}
* 方法来保存测量结果的宽度和高度.如果忘记将导致 {@link #measure(int, int)}
* 方法抛出<code>IllegalStateException</code>异常。调用父类的
* {@link #onMeasure(int, int)}是个有效的方法。
* </p>
*
* <p>
* 基类测量的是背景的大小,除非 MeasureSpec 允许超过背景.子类应该重写
* {@link #onMeasure(int, int)} 方法,以为其内容提供更适合的大小.
* 基类测量的是背景的大小,除非 MeasureSpec 允许超过背景子类应该重写
* {@link #onMeasure(int, int)} 方法,以为其内容提供更适合的大小
* </p>
*
* <p>
* 如果重写了该方法,子类要确保其高度和宽度大于等于视图的最小高度和宽度.
* 如果重写了该方法,子类要确保其高度和宽度大于等于视图的最小高度和宽度
* ({@link #getSuggestedMinimumHeight()} 和 {@link #getSuggestedMinimumWidth()})
* </p>
*
Expand Down
32 changes: 14 additions & 18 deletions frameworks/base/core/java/android/widget/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
import android.view.ViewGroup;

/**
* An Adapter object acts as a bridge between an {@link AdapterView} and the
* underlying data for that view. The Adapter provides access to the data items.
* The Adapter is also responsible for making a {@link android.view.View} for
* each item in the data set.
* Adapter 对象是{@link AdapterView}和视图的底层数据之间的桥梁.
* Adapter 提供了访问数据项的功能。另外,Adapter 也负责为数据集中的每一项创建
* {@link android.view.View 视图}。
*
* @see android.widget.ArrayAdapter
* @see android.widget.CursorAdapter
Expand Down Expand Up @@ -77,26 +76,23 @@ public interface Adapter {
boolean hasStableIds();

/**
* Get a View that displays the data at the specified position in the data set. You can either
* create a View manually or inflate it from an XML layout file. When the View is inflated, the
* parent View (GridView, ListView...) will apply default layout parameters unless you use
* {@link android.view.LayoutInflater#inflate(int, android.view.ViewGroup, boolean)}
* to specify a root view and to prevent attachment to the root.
* 获取用于显示数据集中指定位置上的数据的视图。你可以手工创建一个视图,
* 也可以从 XML 布局文件中展开视图。展开视图时,父视图(GridView、ListView 等)
* 将应用默认的布局参数,除非你使用{@link
* android.view.LayoutInflater#inflate(int, android.view.ViewGroup, boolean)}
* inflate(int, android.view.ViewGroup, boolean)指定根视图,并指定附加到根元素。
*
* @param position 要从适配器中取得的视图的位置.
* @param convertView The old view to reuse, if possible. Note: You should check that this view
* is non-null and of an appropriate type before using. If it is not possible to convert
* this view to display the correct data, this method can create a new view.
* @param parent The parent that this view will eventually be attached to
* @return A View corresponding to the data at the specified position.
* @param convertView 要重用的旧视图,如果可能。注意,在使用之前你应该检查该视图是否非空,
* 并且是适当的类型。如果不能转化该视图来正确显示数据,该方法将创建新视图。
* @param parent 该视图最终关联到的父视图。
* @return 指定位置的数据对应的视图。
*/
View getView(int position, View convertView, ViewGroup parent);

/**
* An item view type that causes the {@link AdapterView} to ignore the item
* view. For example, this can be used if the client does not want a
* particular view to be given for conversion in
* {@link #getView(int, View, ViewGroup)}.
* 使{@link AdapterView}忽略视图条目的视图类型。例如,当客户端不希望特定视图被
* {@link #getView(int, View, ViewGroup)}转换时,可以使用该类型。
*
* @see #getItemViewType(int)
* @see #getViewTypeCount()
Expand Down

0 comments on commit 770a97b

Please sign in to comment.