public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shuping);
db=new DB(this);
DisplayMetrics dm=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
widthp=dm.widthPixels;
heightp=dm.heightPixels;//这里有问题
// ScrollView001=(ScrollView)this.findViewById(R.id.scroll001);
// Linear01 =(LinearLayout)this.findViewById(R.id.Linear01);
// Linear01.removeAllViews();
final Button btn01=(Button) this.findViewById(R.id.btn01);
final Button btn02=(Button) this.findViewById(R.id.btn02);
final Button btn03=(Button) this.findViewById(R.id.btn03);
final Button btn04=(Button) this.findViewById(R.id.btn04);
为啥加上这个调试就出错,去掉就没问题,能够不能够在onCreate方法中操作这个LinearLayout,或者ScrollView001还是什么问题,为啥添加任意一个就出错????????????
// ScrollView001=(ScrollView)this.findViewById(R.id.scroll001);
// Linear01 =(LinearLayout)this.findViewById(R.id.Linear01);
// Linear01.removeAllViews();
布局这样大概这样 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollbarAlwaysDrawHorizontalTrack="false"
android:id="@+id/scroll001"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Linear01">
</LinearLayout>
</HorizontalScrollView>
super.onCreate(savedInstanceState);
setContentView(R.layout.shuping);
db=new DB(this);
DisplayMetrics dm=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
widthp=dm.widthPixels;
heightp=dm.heightPixels;//这里有问题
// ScrollView001=(ScrollView)this.findViewById(R.id.scroll001);
// Linear01 =(LinearLayout)this.findViewById(R.id.Linear01);
// Linear01.removeAllViews();
final Button btn01=(Button) this.findViewById(R.id.btn01);
final Button btn02=(Button) this.findViewById(R.id.btn02);
final Button btn03=(Button) this.findViewById(R.id.btn03);
final Button btn04=(Button) this.findViewById(R.id.btn04);
为啥加上这个调试就出错,去掉就没问题,能够不能够在onCreate方法中操作这个LinearLayout,或者ScrollView001还是什么问题,为啥添加任意一个就出错????????????
// ScrollView001=(ScrollView)this.findViewById(R.id.scroll001);
// Linear01 =(LinearLayout)this.findViewById(R.id.Linear01);
// Linear01.removeAllViews();
布局这样大概这样 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollbarAlwaysDrawHorizontalTrack="false"
android:id="@+id/scroll001"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Linear01">
</LinearLayout>
</HorizontalScrollView>
你说的重启就没问题了,可能是eclipse解析工程时出的问题,有时候eclipse就会抽风。
重启eclipse或者先删除工程,再import工程也能解决问题。