时间:2021-05-19
这里说是框架,说的大了点,其实没有那么复杂,只是一个容易扩展的基类而已。不过至少算是框架类的代码。
复制代码 代码如下:
package arui;
import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewManager;
import android.widget.FrameLayout;
/**
* Base class for panel.
*
*/
public abstract class BasePanel {
/**
* left up position
*/
public static final int LEFT_UP = 1;
/**
* right up position
*/
public static final int RIGHT_UP = 2;
/**
* left bottom position
*/
public static final int LEFT_BOTTOM = 3;
/**
* right bottom position
*/
public static final int RIGHT_BOTTOM = 4;
private static final int DEFAULT_MARGIN = 10;
private static final int SHOW_PANEL = 0;
private Activity activity;
private LayoutParams parameters;
private View view = null;
private int layoutId;
/**
* constructor.
*
* @param activity
* this panel will be attached to the activity
* @param layoutId
* the panel's layout id
*/
public BasePanel(Activity activity, int layoutId) {
this.activity = activity;
this.layoutId = layoutId;
}
/**
* The developer can use this method to add the panel to the Activity.
*
* @param act
* Activity
* @param params
* LayoutParams
*/
public void attach(LayoutParams params) {
parameters = params;
mHandler.sendMessage(mHandler.obtainMessage(SHOW_PANEL));
}
/**
* The developer can use this method to add the panel to the Activity.
*
* @param act
* Activity
* @param position
* int. You can use BasePanel.LEFT_UP,BasePanel.RIGHT_UP,
* BasePanel.RIGHT_BOTTOM or BasePanel.LEFT_BOTTOM.
*/
public void attach(int position) {
attach(position, DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN,
DEFAULT_MARGIN);
}
/**
* The developer can use this method to add the panel to the Activity.
*
* @param act
* Activity
* @param position
* int. You can use BasePanel.LEFT_UP,BasePanel.RIGHT_UP,
* BasePanel.RIGHT_BOTTOM or BasePanel.LEFT_BOTTOM.
* @param leftMargin
* int, left margin.
* @param topMargin
* int, top margin.
* @param rightMargin
* int, right margin.
* @param bottomMargin
* int, bottom margin.
*
*/
public void attach(int position, int leftMargin, int topMargin,
int rightMargin, int bottomMargin) {
FrameLayout.LayoutParams params = null;
params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
switch (position) {
case LEFT_UP:
params.gravity = Gravity.LEFT;
break;
case RIGHT_UP:
params.gravity = Gravity.RIGHT;
break;
case LEFT_BOTTOM:
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
break;
case RIGHT_BOTTOM:
params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
break;
default:
break;
}
attach(params);
}
/**
* The developer can use this method to remove the panel from the Activity.
*
*/
public void remove() {
if (view != null) {
ViewManager mViewManager = (ViewManager) view.getParent();
if (mViewManager != null) {
mViewManager.removeView(view);
}
}
}
private Handler mHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SHOW_PANEL:
if (view == null) {
LayoutInflater factory = LayoutInflater.from(activity);
view = factory.inflate(layoutId, null);
}
dealwithPanel(view);
remove();
activity.addContentView(view, parameters);
break;
}
}
};
/**
* do something with this panel.
*
* @param view
* View of the panel
*/
public abstract void dealwithPanel(View view);
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文介绍了Android冷启动实现app秒开的实现代码,分享给大家,具体如下:AndroidManifest里对应activity添加属性android:the
AutoCompleteTextView是实现动态匹配输入内容的一种输入框(EditText),如输入“and”时,会提示“Android”效果图:实现代码:p
在最近做的一个将原来的旧系统翻新改造的项目中,为了在个别展示位置与原系统一直,研究了一下Easyui的panel面板,在panel的面板中动态添加Linkbut
本文为大家分享了Android动态布局的实现代码,供大家参考,具体内容如下内容如下:介绍多种实现动态布局的方法,以及如何用代码来调整View位置这里只介绍三种布
本文实例讲述了Android实现动态向Gallery中添加图片及倒影与3D效果的方法。分享给大家供大家参考,具体如下:在Android中gallery可以提供一