Java Code Examples for android.widget.FrameLayout#setOnDragListener()

The following examples show how to use android.widget.FrameLayout#setOnDragListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoteControlView.java    From RemoteControlView with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    setWillNotDraw(false);
    mPhonePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackPath = new Path();
    // 不使用硬件加速,否则虚线显示不出
    setLayerType(LAYER_TYPE_SOFTWARE, null);
    // 拖拽有效区域
    frameLayout = new FrameLayout(context);
    frameLayout.setBackgroundColor(Color.parseColor(CONTENT_COLOR));
    frameLayout.setOnDragListener(this);
    addView(frameLayout);
    // 提示文字
    mTextView = new TextView(context);
    mTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
    mTextView.setTextColor(Color.WHITE);
    mTextView.setText("长按并拖拽下方按钮到这里");
    LayoutParams fl = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    fl.gravity = Gravity.CENTER;
    mTextView.setLayoutParams(fl);
    mTextView.measure(0, 0);
    addView(mTextView);
}
 
Example 2
Source File: MainActivity.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView dragText = findViewById(R.id.text_drag);
    FrameLayout targetFrame = findViewById(R.id.frame_target);

    //Set up drop target listener.
    targetFrame.setOnDragListener(new DropTargetListener(this));

    //Set up draggable item listener.
    dragText.setOnLongClickListener(new TextViewLongClickListener());
}