Java Code Examples for android.widget.RelativeLayout.LayoutParams#setMargins()

The following examples show how to use android.widget.RelativeLayout.LayoutParams#setMargins() . 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: InfoAdapter.java    From douyin with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {
    RelativeLayout layout = new RelativeLayout(getContext());
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, dp2px(45));
    layout.setLayoutParams(layoutParams);

    TextView title = new TextView(getContext());
    title.setId(0);
    LayoutParams title_params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    title_params.addRule(RelativeLayout.CENTER_VERTICAL);
    title_params.setMargins(dp2px(18), 0, 0, 0);
    title.setLayoutParams(title_params);

    TextView subTitle = new TextView(getContext());
    subTitle.setId(1);
    LayoutParams subTitle_params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    subTitle_params.addRule(RelativeLayout.CENTER_VERTICAL);
    subTitle_params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    subTitle_params.setMargins(0, 0, dp2px(20), 0);
    subTitle.setLayoutParams(subTitle_params);

    layout.addView(title);
    layout.addView(subTitle);
    return layout;
}
 
Example 2
Source File: ChannelFragmentAdapter.java    From letv with Apache License 2.0 6 votes vote down vote up
private ImageView addMirrorView(ViewGroup parent, RecyclerView recyclerView, View view) {
    view.destroyDrawingCache();
    view.setDrawingCacheEnabled(true);
    ImageView mirrorView = new ImageView(recyclerView.getContext());
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
    mirrorView.setImageBitmap(bitmap);
    view.setDrawingCacheEnabled(false);
    int[] locations = new int[2];
    view.getLocationOnScreen(locations);
    int[] parenLocations = new int[2];
    recyclerView.getLocationOnScreen(parenLocations);
    LayoutParams params = new LayoutParams(bitmap.getWidth(), bitmap.getHeight());
    params.setMargins(locations[0], (locations[1] - parenLocations[1]) + UIsUtils.dipToPx(44.0f), 0, 0);
    parent.addView(mirrorView, params);
    return mirrorView;
}
 
Example 3
Source File: CuxtomCamActivity.java    From CuXtomCam with Apache License 2.0 6 votes vote down vote up
/**
 * initialize video recording UI with timer
 */
private void initVideoRecordingUI(String initializeTime) {
	LayoutParams rl_param = new LayoutParams(
			android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
			android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
	rl_param.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
	rl_param.addRule(RelativeLayout.CENTER_HORIZONTAL);
	rl_param.addRule(RelativeLayout.ALIGN_BOTTOM, mPreview.getId());
	rl_param.setMargins(0, 0, 0, 30);
	tv_recordingDuration.setText(initializeTime);
	tv_recordingDuration.setTextSize(28);
	tv_recordingDuration.setLayoutParams(rl_param);
	previewCameraLayout.addView(tv_recordingDuration);
	mExecutorService = Executors.newSingleThreadScheduledExecutor();
	totalVideoDuration = 0;
	mExecutorService.scheduleAtFixedRate(recordingTimer, 1, 1,
			TimeUnit.SECONDS);
}
 
Example 4
Source File: X8VerticalSeekBarValueLayout.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void onProgress(X8VerticalSeekBar slideView, int progress) {
    LayoutParams lp = new LayoutParams(this.tvValue.getLayoutParams());
    lp.setMargins(this.verticalSeekBar.getDestX(), this.verticalSeekBar.getDestY(), 0, 0);
    this.tvValue.setLayoutParams(lp);
    this.curValue = this.seekBarMin + progress;
    this.tvValue.setText("" + (((float) this.curValue) / 10.0f) + this.prex);
    this.mSearchResultsSubject.onNext(Integer.valueOf(this.curValue));
}
 
Example 5
Source File: ChannelTabPageIndicator.java    From letv with Apache License 2.0 5 votes vote down vote up
protected void addTab(int index, CharSequence text, int iconResId) {
    TabView tabView = new TabView(this, getContext(), text);
    tabView.setIndex(index);
    tabView.setFocusable(true);
    tabView.setOnClickListener(this.mTabClickListener);
    if (iconResId != 0) {
        tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }
    int width = this.mMeanWidth == -1 ? getTabWidth(text) : this.mMeanWidth;
    if (this.mMeanWidth != -1) {
        tabView.setSize(this.mMeanWidth, UIsUtils.dipToPx(38.0f));
    } else {
        tabView.setSize(width, UIsUtils.dipToPx(38.0f));
    }
    RelativeLayout relativeLayout = new RelativeLayout(this.mContext);
    relativeLayout.setGravity(17);
    relativeLayout.setLayoutParams(new LayoutParams(-2, UIsUtils.dipToPx(38.0f)));
    LayoutParams params = new LayoutParams(-2, UIsUtils.dipToPx(38.0f));
    params.setMargins(TAB_MARGIN, 0, TAB_MARGIN, 0);
    tabView.setLayoutParams(params);
    relativeLayout.addView(tabView);
    if (this.mIsHome) {
        ThemeDataManager.getInstance(this.mContext).setContentTheme(tabView, ThemeDataManager.NAME_TOP_NAVIGATION_COLOR);
    }
    ImageView imageView = new ImageView(this.mContext);
    LayoutParams imageViewParams = new LayoutParams(width, UIsUtils.dipToPx(2.0f));
    imageViewParams.setMargins(TAB_MARGIN, UIsUtils.dipToPx(36.0f), TAB_MARGIN, 0);
    imageView.setLayoutParams(imageViewParams);
    relativeLayout.addView(imageView);
    imageView.setBackgroundDrawable(getResources().getDrawable(2130838177));
    if (this.mIsHome) {
        ThemeDataManager.getInstance(this.mContext).setShapeSelectorViewTheme(imageView, ThemeDataManager.NAME_TOP_NAVIGATION_COLOR, 2, true);
    }
    this.mTabLayout.addView(relativeLayout);
}
 
Example 6
Source File: PlayerActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void setupController() {

        int w = (int) (mMetrics.widthPixels * MEDIA_BAR_WIDTH);
        int h = (int) (mMetrics.heightPixels * MEDIA_BAR_HEIGHT);
        int marginLeft = (int) (mMetrics.widthPixels * MEDIA_BAR_LEFT_MARGIN);
        int marginTop = (int) (mMetrics.heightPixels * MEDIA_BAR_TOP_MARGIN);
        int marginRight = (int) (mMetrics.widthPixels * MEDIA_BAR_RIGHT_MARGIN);
        int marginBottom = (int) (mMetrics.heightPixels * MEDIA_BAR_BOTTOM_MARGIN);
        LayoutParams lp = new LayoutParams(w, h);
        lp.setMargins(marginLeft, marginTop, marginRight, marginBottom);
        mControllers.setLayoutParams(lp);
        mStartText.setText(getResources().getString(R.string.init_text));
        mEndText.setText(getResources().getString(R.string.init_text));
    }
 
Example 7
Source File: PlayerActivity.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
private void setupController() {

        int w = (int) (mMetrics.widthPixels * MEDIA_BAR_WIDTH);
        int h = (int) (mMetrics.heightPixels * MEDIA_BAR_HEIGHT);
        int marginLeft = (int) (mMetrics.widthPixels * MEDIA_BAR_LEFT_MARGIN);
        int marginTop = (int) (mMetrics.heightPixels * MEDIA_BAR_TOP_MARGIN);
        int marginRight = (int) (mMetrics.widthPixels * MEDIA_BAR_RIGHT_MARGIN);
        int marginBottom = (int) (mMetrics.heightPixels * MEDIA_BAR_BOTTOM_MARGIN);
        LayoutParams lp = new LayoutParams(w, h);
        lp.setMargins(marginLeft, marginTop, marginRight, marginBottom);
        mControllers.setLayoutParams(lp);
        mStartText.setText(getResources().getString(R.string.init_text));
        mEndText.setText(getResources().getString(R.string.init_text));
    }
 
Example 8
Source File: PlayerActivity.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
private void setupController() {

        int w = (int) (mMetrics.widthPixels * MEDIA_BAR_WIDTH);
        int h = (int) (mMetrics.heightPixels * MEDIA_BAR_HEIGHT);
        int marginLeft = (int) (mMetrics.widthPixels * MEDIA_BAR_LEFT_MARGIN);
        int marginTop = (int) (mMetrics.heightPixels * MEDIA_BAR_TOP_MARGIN);
        int marginRight = (int) (mMetrics.widthPixels * MEDIA_BAR_RIGHT_MARGIN);
        int marginBottom = (int) (mMetrics.heightPixels * MEDIA_BAR_BOTTOM_MARGIN);
        LayoutParams lp = new LayoutParams(w, h);
        lp.setMargins(marginLeft, marginTop, marginRight, marginBottom);
        mControllers.setLayoutParams(lp);
        mStartText.setText(getResources().getString(R.string.init_text));
        mEndText.setText(getResources().getString(R.string.init_text));
    }
 
Example 9
Source File: PlayerActivity.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
private void setupController() {

        int w = (int) (mMetrics.widthPixels * MEDIA_BAR_WIDTH);
        int h = (int) (mMetrics.heightPixels * MEDIA_BAR_HEIGHT);
        int marginLeft = (int) (mMetrics.widthPixels * MEDIA_BAR_LEFT_MARGIN);
        int marginTop = (int) (mMetrics.heightPixels * MEDIA_BAR_TOP_MARGIN);
        int marginRight = (int) (mMetrics.widthPixels * MEDIA_BAR_RIGHT_MARGIN);
        int marginBottom = (int) (mMetrics.heightPixels * MEDIA_BAR_BOTTOM_MARGIN);
        LayoutParams lp = new LayoutParams(w, h);
        lp.setMargins(marginLeft, marginTop, marginRight, marginBottom);
        mControllers.setLayoutParams(lp);
        mStartText.setText(getResources().getString(R.string.init_text));
        mEndText.setText(getResources().getString(R.string.init_text));
    }
 
Example 10
Source File: TagViewRight.java    From school_shop with MIT License 4 votes vote down vote up
private void initMove() {
		OnTouchListener onTouchListener = new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN:
					lastX=(int)event.getRawX();
		            lastY=(int)event.getRawY();
//		            System.out.println("lastX="+lastX);
					break;
				case MotionEvent.ACTION_MOVE:
					int area = rLayout.getHeight();
					int dx=(int)event.getRawX()-lastX;
		            int dy=(int)event.getRawY()-lastY;
		            int top=v.getTop()+dy;
		            int left=v.getLeft()+dx;
		            if(top<=0) top=0;
		            if(left<=0) left=0;
//		            System.out.println("screenHeight="+screenHeight);
		            if(top>=screenHeight-area)
		            {
		                top=screenHeight-area;
		            }
		            if(left>=screenWidth-rLayout.getWidth())
		            {
		                left=screenWidth-rLayout.getWidth();
		            }
//		            System.out.println("left="+left+"top="+top);
//		            v.layout(left, top, left+rLayout.getWidth(), top+area);
		            LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		            lp.setMargins(left, top, left+rLayout.getWidth(), top+area);
		            v.setLayoutParams(lp);
		            position.setXplace(left);
		            position.setYplace(top);
		            lastX=(int)event.getRawX();
		            lastY=(int)event.getRawY();
		            break;
		          case MotionEvent.ACTION_UP:
		        	  break;
				}
				return false;
			}
		};
		
		rLayout.setOnTouchListener(onTouchListener);
	}
 
Example 11
Source File: UIImagePager.java    From Auie with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 初始化控件
 */
private View createContentView() {
	
	rootContainer = new RelativeLayout(context);
	rootContainer.setBackgroundColor(Color.parseColor("#000000"));
	rootContainer.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
	
	LayoutParams contentParams = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);
	contentParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	contentContainer = new ViewPager(context);
	contentContainer.setAdapter(imageAdapter);
	contentContainer.setLayoutParams(contentParams);
	contentContainer.setOnPageChangeListener(onPageChangeListener);
	
	LayoutParams params = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);
	params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
	indexContainer = new LinearLayout(context);
	indexContainer.setLayoutParams(params);
	indexContainer.setPadding(0, 0, 0, DP * 20);
	indexContainer.setGravity(Gravity.CENTER);
	indexContainer.setOrientation(LinearLayout.HORIZONTAL);
	
	LayoutParams params2 = new LayoutParams(60 * DP, 32 * DP);
	params2.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
	params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
	params2.setMargins(10 * DP, 0, 0, 10 * DP);
	actionButton = new UIButton(context);
	actionButton.setLayoutParams(params2);
	actionButton.setText("删除");
	actionButton.setTextSize(14);
	actionButton.setVisibility(View.GONE);
	actionButton.setTextColor(Color.WHITE);
	actionButton.setBackgroundColor(Color.RED);
	actionButton.setOnClickListener(onClickListener);
	
	rootContainer.addView(contentContainer);
	rootContainer.addView(indexContainer);
	rootContainer.addView(actionButton);
	
	return rootContainer;
}