0

嗨,我在将按钮放置在屏幕底部时遇到问题,我已经将其布局,并且在 Eclipse 的图形布局中,它看起来正是我想要的,但是当我在设备上运行它时,按钮都转到了非常底端筛分位置相同。所以只有一个按钮可见。有谁知道这是为什么,或者你知道如何将东西 s 放在底部并加一点填充?

这是我尝试过的

<?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);


}



}
4

3 回答 3

1

我认为您混淆了一些属性。

在您的第二个按钮中,不要将“+”运算符添加到 id,因为它正在创建一个新按钮。只需将其删除并留下“@”即可。

记住 '+' 添加到 id 和 '@' 引用它。

于 2012-06-27T20:55:53.327 回答
0

我实际上在我的项目中尝试了您的布局,并且两个按钮放置正确。

您确定您没有在代码中执行任何其他操作吗?

于 2012-06-27T20:49:50.377 回答
0

相对布局是相对于作为 ViewGroup 的 RelativeLayout 容器内的其他项目。因此,例如,您可以在 pm 的描述中指定 android:layout_leftOf="@+id/fm"。如果你想要填充,你也可以像按钮内部一样使用边距和填充。

android:layout_marginBottom="20dip" 
android:layout_leftOf="@+id/fm"
android:paddingBottom="10dip"
于 2012-06-27T20:56:02.970 回答