我的.xml:为什么RelativeLayout.ALIGN_PARENT_RIGHT不起作用?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.eleizo.firstapplication.MainActivity"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/topRL">
</RelativeLayout>
....
我说我的自定义的ImageView对象的RelativeLayout topRL.addView(map);
构造定制的ImageView的是:
public CustomImageView(Context context) {
super(context);
init();
}
public CustomImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,1);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,1);
setBackgroundColor(Color.BLUE);
this.setWillNotDraw(false);
setLayoutParams(params);
}
上创建:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.example.eleizo.firstapplication.R.layout.activity_main);
RL = (RelativeLayout) findViewById(R.id.topRL);
Context context = getApplicationContext();
map = new CustomImageView(context);
RL.addView(map,map.params);
但RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.ALIGN_PARENT_BOTTOM
没有按” t工作:在map.setImageBitmap(input);
之后,我在左上角看到我的图像。
我希望图像的右下角位于RelativeLayout的右下角,与图像的大小无关。
我在哪里犯了错误?
不工作params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); – Elena
添加imageView到relativelayout后,我将位图添加到自定义ImageView中。也许是因为我有一些错误? – Elena