Android按钮不会出现在我的TextView上方

时间:2013-12-18 10:45:50

标签: android button layout relativelayout

我正在做一个简单的蓝牙应用程序,以控制汽车的窗口(仅用于研究)。

布局应该是两个按钮(向上窗口和向下窗口)和一个TextView来打印我的动作和参数的响应。

问题是,这两个按钮都不会出现在我的应用中:(

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/btn_window_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="@string/btn_window_up" />

<Button
    android:id="@+id/btn_window_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/btn_window_up"
    android:text="@string/btn_window_down" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/btn_window_down"
    android:text="&quot;Demo ADK V1.0&quot;" />

</RelativeLayout>

有没有人建议我如何解决这个问题?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    RxThread rxThread = new RxThread();
    MessageStructure demoTxMsg = new MessageStructure();

    ReturnCode returnCode = null;
    ArrayList<String> deviceList = new ArrayList<String>();

    Button btnWindowDown = (Button) findViewById(R.id.btn_window_down);
    Button btnWindowUp = (Button) findViewById(R.id.btn_window_up);

    tv = new TextView(this);
}

这里是Java代码

和清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ixxat.adk.demo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="13" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".Demo_ADKActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

4 个答案:

答案 0 :(得分:0)

试试这段代码。它对我有用。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/btn_window_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/btn_window_up" />

<Button
    android:id="@+id/btn_window_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/btn_window_up"
    android:text="@string/btn_window_down" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/btn_window_down"
    android:text="sample text here" />

</RelativeLayout>

答案 1 :(得分:0)

试试这个..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


<Button
    android:id="@+id/btn_window_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BTN 1" />

<Button
    android:id="@+id/btn_window_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BTN 2" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Your text view goes over here" />

</LinearLayout>

或者像这样...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

<Button
    android:layout_weight="1"
    android:id="@+id/btn_window_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BTN 1" />

<Button
    android:layout_weight="1"
    android:id="@+id/btn_window_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BTN 2" />

</LinearLayout>

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Your text view goes over here" />

</LinearLayout>

答案 2 :(得分:0)

简单易用的方法是使用LinearLayoutandroid:orientation="vertical"

答案 3 :(得分:0)

试试

它完美展现了布局的所有内容..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/RelativeLayout1"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" >

    <Button
        android:id="@+id/btn_window_up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/btn_window_up" />

    <Button
        android:id="@+id/btn_window_down"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/btn_window_up"
        android:text="@string/btn_window_down" />

    <TextView
        android:id="@+id/TextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn_window_down"
        android:layout_marginTop="10dp"
        android:padding="10dp"
        android:textColor="@android:color/black"
        android:background="@android:color/white"
        android:layout_centerHorizontal="true"
        android:text="&quot;Demo ADK V1.0&quot;" />
</RelativeLayout>

相关问题