嗨,我有一个问题,在屏幕的底部放置按钮我已经把它放在了eclipse的图形布局中它看起来我想要它但是当我在设备上运行时按钮都去了到最底层的筛选同一个位置。所以只能看到一个按钮。有没有人知道为什么这是或者你知道如何用一些填充物将东西放在底部?
继承人我试过的事情
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_background_credits"
android:orientation="vertical" >
<Button
android:id="@+id/fm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="38dp"
android:background="@drawable/fmbtn" />
<Button
android:id="@+id/ph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/fm"
android:layout_alignLeft="@+id/fm"
android:background="@drawable/visitphbtn" />
</RelativeLayout>
继承我的代码,我将这个视图膨胀
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//Check Preferences which sets UI
setContentView(R.layout.singlenews);
findViewById(R.id.progress).setVisibility(View.GONE);
loadData();
Button backbtn = (Button) findViewById(R.id.backbtn);
//Listening to button event
backbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent previousScreen = new Intent(getApplicationContext(), InfoActivity.class);
startActivity(previousScreen);
}
});
}
public void loadData(){
name = getIntent().getStringExtra("name");
Log.v("lc", "infoname=" + name);
if (name.equals(name1")) {
NewsView = LayoutInflater.from(getBaseContext()).inflate(R.layout.infodetail,
null);
TextView headerText = (TextView) findViewById(R.id.header_text);
headerText.setText("About name1");
TextView mainText = (TextView) NewsView.findViewById(R.id.maintext);
mainText.setText("name1");
ImageView NewsImage = (ImageView)NewsView.findViewById(R.id.imageView2);
NewsImage.setImageDrawable(getResources().getDrawable(R.drawable.ic_logo_evostik));
}
if (name.equals("name2")) {
NewsView = LayoutInflater.from(getBaseContext()).inflate(R.layout.infodetail,
null);
TextView headerText = (TextView) findViewById(R.id.header_text);
headerText.setText("About name2");
TextView mainText = (TextView) NewsView.findViewById(R.id.maintext);
mainText.setText("name2");
ImageView NewsImage = (ImageView)NewsView.findViewById(R.id.imageView2);
NewsImage.setImageDrawable(getResources().getDrawable(R.drawable.ic_logo_pitchero));
}
if (name.equals("name3")) {
NewsView = LayoutInflater.from(getBaseContext()).inflate(R.layout.creditsdetail,
null);
TextView headerText = (TextView) findViewById(R.id.header_text);
headerText.setText("name3");
Button phbtn=(Button)NewsView.findViewById(R.id.ph);
phbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Uri uri = Uri.parse("http://www.pitchero.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
Button fmbtn=(Button)NewsView.findViewById(R.id.fm);
fmbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Uri uri = Uri.parse("http://www.fantasticmedia.co.uk/mobile/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
}
ListView list = getListView();
list.setVerticalFadingEdgeEnabled(false);
Log.v("BGThread", "Filled results");
adapter = new MergeAdapter();
adapter.addView(NewsView);
setListAdapter(adapter);
}
}
答案 0 :(得分:1)
我认为你有一些混淆的属性。
在你的第二个按钮中不要将'+'运算符添加到id,因为它正在创建一个新的运算符。只需删除它并离开'@'。
记住'+'添加到id,'@'引用它。
答案 1 :(得分:0)
我实际上在项目中尝试了你的布局并正确放置了两个按钮。
您确定没有在代码中执行任何其他操作吗?
答案 2 :(得分:0)
相对布局相对于RelativeLayout容器内的其他项目是ViewGroup。例如,你可以在pm的描述中指定android:layout_leftOf =“@ + id / fm”。如果你想要填充,你也可能会在按钮内部使用边距和填充来表示。
android:layout_marginBottom="20dip"
android:layout_leftOf="@+id/fm"
android:paddingBottom="10dip"