为什么下面的图像视图android:layout_不工作

为什么下面的图像视图android:layout_不工作,android,android-layout,android-imageview,textview,Android,Android Layout,Android Imageview,Textview,在此页面中,@+id/photo_区域是动态生成的,因为我希望宽度与高度对齐,所以我编写了以下xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_pa

在此页面中,
@+id/photo_区域是动态生成的,因为我希望宽度与高度对齐,所以我编写了以下xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/share_bg" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:overScrollMode="never" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/photo_area"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/share_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/photo_area"
                android:layout_above="@+id/share_content"
                android:layout_marginLeft="20dp"
                android:text="@string/share_title"
                android:textColor="@android:color/white" />

            <EditText
                android:id="@+id/share_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/share_submit"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:background="@drawable/custom_textarea"
                android:gravity="top|left"
                android:lines="5"
                android:scrollbars="vertical"
                android:text="@string/default_msg" />

            <ImageView
                android:id="@+id/share_submit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_margin="20dp"
                android:src="@drawable/photo_taken_btn_submit" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

在程序中,我在照片上设置了参数

    /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.share_pic_form);

            ctx = this;

            prefs = ctx.getSharedPreferences("userInfo", 0);
            editor = prefs.edit();

            tracker = EasyTracker.getInstance(this);

            permission = new ArrayList<String>();
            permission.add("email");

            Utility.setHeader(this,R.string.selfie_header,false);

            Session session = Session.getActiveSession();
            if (session == null) {
                if (savedInstanceState != null) {
                    session = Session.restoreSession(this, null, callback, savedInstanceState);
                }
                if (session == null) {
                    session = new Session(this);
                }
                Session.setActiveSession(session);
                if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
                    session.openForRead(new Session.OpenRequest(this).setPermissions(permission).setCallback(callback));
                }
            }

            photoArea = (ImageView) findViewById(R.id.photo_area);
            int size = (int)(Utility.getScreenWidth(this)); 
            RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(size, size);
            imgParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
             //imgParams.addRule(RelativeLayout.ABOVE, R.id.share_title);
            photoArea.setAdjustViewBounds(true);
            photoArea.setLayoutParams(imgParams);
            photoArea.setBackgroundResource(android.R.color.darker_gray);
            photoArea.getBackground().setAlpha(204); // = 0.8 alpha

            shareTitle = (TextView) findViewById(R.id.share_title);
            shareContent = (EditText) findViewById(R.id.share_content);

            if (getIntent() != null) {
                Intent intent = getIntent();
                fileUri = (String) intent.getStringExtra("photo");
                catId = (String) intent.getStringExtra("catId");
            } else if (savedInstanceState != null){
                mBitmap = (Bitmap) savedInstanceState.getParcelable("bitmap") == null ? null : (Bitmap) savedInstanceState.getParcelable("bitmap");
                catId = (String) savedInstanceState.getString("catId");
            }

            FileInputStream inputStream = null;
            File imgSelected = new File(fileUri);

            try {
                inputStream = new FileInputStream(imgSelected);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Toast.makeText(ctx, ctx.getResources().getString(R.string.get_photo_error), Toast.LENGTH_SHORT).show();
                finish();
            }

            mBitmap = Utility.decodeBitmap(inputStream, 1280, 960);

            if (mBitmap == null) {
                Toast.makeText(ctx, ctx.getResources().getString(R.string.get_photo_error), Toast.LENGTH_SHORT).show();
                finish();
            } else {
                photoArea.setImageBitmap(mBitmap);                  
                sharePhotoBtn = (ImageView) findViewById(R.id.share_submit);
                sharePhotoBtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        tracker.send(MapBuilder.createEvent("form_button","Category_form","SubmitnShare_" + Utility.getLocale(ctx),null).build());
                        performPublish(PendingAction.POST_PHOTO);
                    }
                });
            }

        }


The problem is , in the xml /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.share_pic_form);

        ctx = this;

        prefs = ctx.getSharedPreferences("userInfo", 0);
        editor = prefs.edit();

        tracker = EasyTracker.getInstance(this);

        permission = new ArrayList<String>();
        permission.add("email");

        Utility.setHeader(this,R.string.selfie_header,false);

        Session session = Session.getActiveSession();
        if (session == null) {
            if (savedInstanceState != null) {
                session = Session.restoreSession(this, null, callback, savedInstanceState);
            }
            if (session == null) {
                session = new Session(this);
            }
            Session.setActiveSession(session);
            if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
                session.openForRead(new Session.OpenRequest(this).setPermissions(permission).setCallback(callback));
            }
        }

        photoArea = (ImageView) findViewById(R.id.photo_area);
        int size = (int)(Utility.getScreenWidth(this)); 
        RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(size, size);
        imgParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
         //imgParams.addRule(RelativeLayout.ABOVE, R.id.share_title);
        photoArea.setAdjustViewBounds(true);
        photoArea.setLayoutParams(imgParams);
        photoArea.setBackgroundResource(android.R.color.darker_gray);
        photoArea.getBackground().setAlpha(204); // = 0.8 alpha

        shareTitle = (TextView) findViewById(R.id.share_title);
        shareContent = (EditText) findViewById(R.id.share_content);

        if (getIntent() != null) {
            Intent intent = getIntent();
            fileUri = (String) intent.getStringExtra("photo");
            catId = (String) intent.getStringExtra("catId");
        } else if (savedInstanceState != null){
            mBitmap = (Bitmap) savedInstanceState.getParcelable("bitmap") == null ? null : (Bitmap) savedInstanceState.getParcelable("bitmap");
            catId = (String) savedInstanceState.getString("catId");
        }

        FileInputStream inputStream = null;
        File imgSelected = new File(fileUri);

        try {
            inputStream = new FileInputStream(imgSelected);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(ctx, ctx.getResources().getString(R.string.get_photo_error), Toast.LENGTH_SHORT).show();
            finish();
        }

        mBitmap = Utility.decodeBitmap(inputStream, 1280, 960);

        if (mBitmap == null) {
            Toast.makeText(ctx, ctx.getResources().getString(R.string.get_photo_error), Toast.LENGTH_SHORT).show();
            finish();
        } else {
            photoArea.setImageBitmap(mBitmap);                  
            sharePhotoBtn = (ImageView) findViewById(R.id.share_submit);
            sharePhotoBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    tracker.send(MapBuilder.createEvent("form_button","Category_form","SubmitnShare_" + Utility.getLocale(ctx),null).build());
                    performPublish(PendingAction.POST_PHOTO);
                }
            });
        }

    }
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.share_pic_form);
ctx=这个;
prefs=ctx.getSharedReferences(“userInfo”,0);
editor=prefs.edit();
tracker=EasyTracker.getInstance(this);
权限=新建ArrayList();
许可。添加(“电子邮件”);
setHeader(this,R.string.selfie_头,false);
Session=Session.getActiveSession();
if(会话==null){
如果(savedInstanceState!=null){
session=session.restoreSession(this,null,callback,savedInstanceState);
}
if(会话==null){
会话=新会话(本);
}
Session.setActiveSession(Session);
if(session.getState().equals(SessionState.CREATED\u TOKEN\u LOADED)){
session.openForRead(newsession.OpenRequest(this).setPermissions(permission).setCallback(callback));
}
}
photoArea=(ImageView)findViewById(R.id.photo_区域);
int size=(int)(Utility.getScreenWidth(this));
RelativeLayout.LayoutParams imgParams=新的RelativeLayout.LayoutParams(大小、大小);
imgParams.addRule(RelativeLayout.ALIGN\u PARENT\u TOP);
//imgParams.addRule(RelativeLayout.over,R.id.share_title);
photoArea.setAdjustViewBounds(真);
photoArea.setLayoutParams(imgParams);
photoArea.setBackgroundResource(android.R.color.深灰色);
photoArea.getBackground().setAlpha(204);//=0.8 alpha
shareTitle=(TextView)findViewById(R.id.share\u title);
shareContent=(EditText)findViewById(R.id.share\u content);
如果(getIntent()!=null){
Intent=getIntent();
fileUri=(字符串)intent.getStringExtra(“照片”);
catId=(字符串)intent.getStringExtra(“catId”);
}else if(savedInstanceState!=null){
mBitmap=(位图)savedInstanceState.getParcelable(“位图”)==null?null:(位图)savedInstanceState.getParcelable(“位图”);
catId=(字符串)savedInstanceState.getString(“catId”);
}
FileInputStream inputStream=null;
File imgSelected=新文件(fileUri);
试一试{
inputStream=新文件inputStream(imgSelected);
}catch(filenotfounde异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
Toast.makeText(ctx,ctx.getResources().getString(R.string.get\u photo\u error),Toast.LENGTH\u SHORT.show();
完成();
}
mBitmap=Utility.decode位图(inputStream,1280960);
if(mBitmap==null){
Toast.makeText(ctx,ctx.getResources().getString(R.string.get\u photo\u error),Toast.LENGTH\u SHORT.show();
完成();
}否则{
photoArea.setImageBitmap(mBitmap);
sharePhotoBtn=(ImageView)findViewById(R.id.share\u submit);
sharePhotoBtn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
send(MapBuilder.createEvent(“form_按钮”、“Category_表单”、“SubmitnShare_”+Utility.getLocale(ctx),null).build());
性能发布(挂起操作。发布照片);
}
});
}
}
问题是,在第一次创建活动时调用的xml/**中*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.share_pic_form);
ctx=这个;
prefs=ctx.getSharedReferences(“userInfo”,0);
editor=prefs.edit();
tracker=EasyTracker.getInstance(this);
权限=新建ArrayList();
许可。添加(“电子邮件”);
setHeader(this,R.string.selfie_头,false);
Session=Session.getActiveSession();
if(会话==null){
如果(savedInstanceState!=null){
session=session.restoreSession(this,null,callback,savedInstanceState);
}
if(会话==null){
会话=新会话(本);
}
Session.setActiveSession(Session);
if(session.getState().equals(SessionState.CREATED\u TOKEN\u LOADED)){
session.openForRead(newsession.OpenRequest(this).setPermissions(permission).setCallback(callback));
}
}
photoArea=(ImageView)findViewById(R.id.photo_区域);
int size=(int)(Utility.getScreenWidth(this));
RelativeLayout.LayoutParams imgParams=新的RelativeLayout.LayoutParams(大小、大小);
imgParams.addRule(RelativeLayout.ALIGN\u PARENT\u TOP);
//imgParams.addRule(RelativeLayout.over,R.id.share_title);
photoArea.setAdjustViewBounds(真);
photoArea.setLayoutParams(imgParams);
photoArea.setBackgroundResource(android.R.color.深灰色);
photoArea.getBackground().setAlpha(204);//=0.8 alpha
shareTitle=(TextView)findViewById(R.id.share\u title);
shareContent=(EditText)findViewById(R.id.share\u content);
如果(getIntent()!=null