2017-09-29 2 views

答えて

2

このようにしてください。

TextView mTvLine = findViewById(R.id.tv_line); 
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
// add rule 
params.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.ll_status); 
params.setMargins(0, 0, 0, 0); 
mTvLine.setLayoutParams(params); 

NOTE

RelativeLayout.LayoutParams relativeLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 

// Child widget relative to the widget: imageViewId is ABOVE of it 
relativeLayoutParams.addRule(RelativeLayout.ABOVE, imageViewId.getId()); 

// Child widget relative to the widget: imageViewId is BELOW of it 
relativeLayoutParams.addRule(RelativeLayout.BELOW, imageViewId.getId()); 

// Child widget relative to the widget: aligned with the bottom of the imageViewId 
relativeLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, imageViewId.getId()); 

// The following three methods represent the same, indicating that the child widget is at the bottom of the parent widget 
relativeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, -1);// 
relativeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); 
relativeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
0

はい可能ですが、それはあなたがより適切な方法で行うことができる何をしたいのかという兆候である可能性があります。だから、この要求の背後にある理由は何ですか?

あなたは本当に、プログラムの代わりに、XMLレイアウトを経由してそれを実行する必要がある場合、あなたはこのようにそれを行うことができます。注意する

View myView = findViewById(R.layout.my_view); 
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams(); 
params.bottomMargin = 23; // your new value, in pixels 
view.setLayoutParams(params); 

二つ詳細:余白をピクセル単位であるが、XMLのレイアウトがDPSにあり;また、各ビュータイプに対して、独自のレイアウトパラメータタイプにキャストする必要があります。

関連する問題