我是Android世界的新手。我有一个xml布局,我想将其作为子窗口添加到其他xml文件的scrollview。
这是多次插入的布局[offerview.xml] -
必须插入的xml [activity_offer.xml]是 -
活动的Java代码是 -
public class OfferActivity extends Activity {
private static final String name = "Reebok";
private static final String content = "50% off on Reebok Shoes at Reliance Mart";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offer);
View v = LayoutInflater.from(getApplicationContext()).inflate(R.layout.offerview, null);
TextView offerItemTextView = (TextView) v.findViewById(R.id.offerItemTextView);
offerItemTextView.setText(name);
TextView offerContentTextView = (TextView) v.findViewById(R.id.offertextView);
offerContentTextView.setText(content);
ImageView offerImage = (ImageView) v.findViewById(R.id.offerImageView);
offerImage.setBackgroundResource(R.drawable.ps);
((LinearLayout) findViewById(R.id.offersLayout)).addView(v);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.offer, menu);
return true;
}
}
目前我只想尝试包含一次视图。该应用程序崩溃了。
我一直被困在这上面。
答案 0 :(得分:1)
您的layout_width
layout_height
和offersLayout
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/offersLayout">
</LinearLayout>
...
答案 1 :(得分:1)
日志文件说你必须在activity_offer.xml中添加LinerLayout的layout_width atts。 您可以使用merge标记再次使用xml文件