Android按钮不显示在我的文本视图上方
我正在做一个简单的蓝牙应用程序,用来控制车窗,只是为了研究 布局应该是两个按钮“窗口向上”和“窗口向下”,以及一个文本视图,用于打印有关我的操作和参数的响应 问题是,这两个按钮都不会出现在我的应用程序中:Android按钮不显示在我的文本视图上方,android,button,layout,android-relativelayout,Android,Button,Layout,Android Relativelayout,我正在做一个简单的蓝牙应用程序,用来控制车窗,只是为了研究 布局应该是两个按钮“窗口向上”和“窗口向下”,以及一个文本视图,用于打印有关我的操作和参数的响应 问题是,这两个按钮都不会出现在我的应用程序中: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout1" android:layout_width="fill_parent"
<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=""Demo ADK V1.0"" />
</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>
试试这个代码。它对我有用
<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>
试试这个
<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>
最简单的方法是使用android:orientation=vertical的线性布局 它完美地展示了版面的所有内容
<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=""Demo ADK V1.0"" />
</RelativeLayout>
有什么问题?按钮已经显示在Textview上方。您能详细说明您的问题吗?它本身是否未显示在设备或xml页面中?它们不会显示在应用程序中:好的!发布JAVA代码。布局文件的名称是什么?是主菜吗?因为你可能指向了错误的布局文件。当你尝试运行你的应用程序时,你也会出错吗?对我来说不适用:我的文本视图似乎覆盖了所有其他内容。同样没有成功。我现在尝试了将近2天,我认为这是我使用的ADK的一个问题。因此,我只能自己解决一个问题:很抱歉回答得太晚,但我发现了一个问题:setContentView=TextView。。。已重写主ContentView。。。所以按钮被TextView覆盖了