1) WifiDispaly对应文件WifiDisplaySettings.java
2) 里面采用Preference来实现
3) 对Preference的点击调用到onPreferenceTreeClick中,连接或者断开WifiDisplay,summary和title,icon的设置具体追溯到PreferenceActivity.java的preference_header_item.xml
4) Option点击dialog对话框,对应R.layout.wifi_display_option,在createWifiDisplayPreference中创建, p.setWidgetLayoutResource(R.layout.wifi_display_preference);点击事件在WifiDisplayPreference的onBindView中设置,在onClick中响应,wifi_display_preference.xml在Preference中为什么会靠右显示,问题未知?
1. Preference.java onCreateView 关联文件preference.xml
protected View onCreateView(ViewGroup parent) { final LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = layoutInflater.inflate(mLayoutResId, parent, false); final ViewGroup widgetFrame = (ViewGroup) layout .findViewById(com.android.internal.R.id.widget_frame); if (widgetFrame != null) { if (mWidgetLayoutResId != 0) { layoutInflater.inflate(mWidgetLayoutResId, widgetFrame); } else { widgetFrame.setVisibility(View.GONE); } } return layout; }
2. 对setWidgetLayoutResource赋值
public void setWidgetLayoutResource(int widgetLayoutResId) { if (widgetLayoutResId != mWidgetLayoutResId) { // Layout changed mHasSpecifiedLayout = true; } mWidgetLayoutResId = widgetLayoutResId; }3. 如何靠右显示,其实和android:layout_weight="1"相关
type in the "widget_frame" layout. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_vertical" android:paddingEnd="?android:attr/scrollbarSize" android:background="?android:attr/selectableItemBackground" > <ImageView android:id="@+android:id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="15dip" android:layout_marginEnd="6dip" android:layout_marginTop="6dip" android:layout_marginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppearance="?android:attr/textAppearanceLarge" android:ellipsize="marquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignStart="@android:id/title" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="?android:attr/textColorSecondary" android:maxLines="4" /> </RelativeLayout> <!-- Preference should place its actual preference widget here. --> <LinearLayout android:id="@+android:id/widget_frame" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical" android:orientation="vertical" /> </LinearLayout>