我刚升级到Marshmallow,现在我的观点不起作用了

时间:2016-05-12 00:04:08

标签: android imageview android-6.0-marshmallow viewgroup

我认为我最近升级到Android 6.0与我无法在运行应用时显示图片有关。我最近将我的三星S6从Lollipop升级到了Marshmallow,而我所有与Lollipop配合得很好的应用程序现在拒绝在我的xml代码之外显示我的任何视图。有人遇到过这种情况么?如果有人有答案我会非常感激

public class MainActivity extends Activity {

Display mainDisplay;
ViewGroup mainLayout;
RelativeLayout.LayoutParams layoutPositioner;
ImageView pracimg;
float offsetX = 0.0f;
float offsetY = 0.0f;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //this.requestWindowFeature(Window.FEATURE_NO_TITLE);//Remove title bar
    //this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//Hides notification bar
    this.setContentView(R.layout.activity_main);//set content view AFTER ABOVE sequence (to avoid crash)

    mainDisplay = getWindowManager().getDefaultDisplay();
    mainLayout = (ViewGroup) findViewById(R.id.id_layout);

    DisplayMetrics m = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(m);
    int windowHeight = m.heightPixels;
    int windowWidth = m.widthPixels;

    offsetX = (windowWidth / 1440.0f);
    offsetY = (windowHeight / 2560.0f);

    pracimg = new ImageView(this);
    SetPos(0, 0, 1440, 2560);
    pracimg.setImageResource(R.drawable.submarinesandwich);
    pracimg.setLayoutParams(layoutPositioner);
    mainLayout.addView(pracimg);
}

public void SetPos(float x, float y, float width, float height) {
    layoutPositioner = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutPositioner.topMargin = (int) (offsetY * y);
    layoutPositioner.leftMargin = (int) (offsetX * x);
    layoutPositioner.width = (int) (width * offsetX);
    layoutPositioner.height = (int) (height * offsetY);
}

<RelativeLayout
    android:id="@+id/id_layout"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:layout_marginLeft = "0dp"
    android:layout_marginTop = "0dp"
    android:layout_marginRight = "1440dp"
    android:layout_marginBottom = "2560dp"
    android:orientation = "horizontal" >
</RelativeLayout>

0 个答案:

没有答案