Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RelativeLayout不';我不能展示所有的宽度_Android_Android Layout_Android Relativelayout - Fatal编程技术网

Android RelativeLayout不';我不能展示所有的宽度

Android RelativeLayout不';我不能展示所有的宽度,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,我有一个Android中带有RelativeLayout的屏幕,有一个TableLayout和一个TableRow,还有6个小部件:4个TextView和2个按钮 当我在平板电脑大小的仿真器上显示它时,所有的小部件都在。但当我移动到手机大小的模拟器(5英寸)时,两个按钮中的一个半消失在右边 我希望RelativeLayout会在屏幕上显示所有这些。我怎样才能做到这一点 我的亲属声明如下: <RelativeLayout xmlns:android="http://schemas.andro

我有一个Android中带有RelativeLayout的屏幕,有一个TableLayout和一个TableRow,还有6个小部件:4个TextView和2个按钮

当我在平板电脑大小的仿真器上显示它时,所有的小部件都在。但当我移动到手机大小的模拟器(5英寸)时,两个按钮中的一个半消失在右边

我希望RelativeLayout会在屏幕上显示所有这些。我怎样才能做到这一点

我的亲属声明如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:paddingLeft="16dp"
  android:paddingRight="16dp" >

表格布局:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/cancelTable"
  android:layout_below="@+id/pageheader"
  android:layout_width="fill_parent"
android:layout_height="fill_parent" >

TableRow:

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dip" >

TextView的和按钮在活动的onCreate中启动:

    table = (TableLayout) findViewById(R.id.cancelTable);
    table.removeAllViewsInLayout();

    TableRow tr=new TableRow(Edit.this);
    tr.removeAllViewsInLayout();
    int flag = 1;       
    if(flag == 1) {
        TextView b11=new TextView(Edit.this);
        b11.setText("Name");
        b11.setTextColor(Color.RED);
        b11.setTextSize(15);
        tr.addView(b11);

        TextView b4 = new TextView(Edit.this);
        b4.setPadding(10, 0, 0, 0);
        b4.setTextSize(15);
        b4.setText("Text");
        b4.setTextColor(Color.RED);
        tr.addView(b4);

        TextView b5=new TextView(Edit.this);
        b5.setPadding(10, 0, 0, 0);
        b5.setText("Number");
        b5.setTextColor(Color.RED);
        b5.setTextSize(15);
        tr.addView(b5);

        TextView b7=new TextView(Edit.this);
        b7.setPadding(10, 0, 0, 0);
        b7.setText("Time");
        b7.setTextColor(Color.RED);
        b7.setTextSize(15);
        tr.addView(b7);

        TextView b8=new TextView(Edit.this);
        b8.setPadding(10, 0, 0, 0);
        b8.setText("Delete");
        b8.setTextColor(Color.RED);
        b8.setTextSize(15);
        tr.addView(b8);

        TextView b9=new TextView(Edit.this);
        b9.setPadding(10, 0, 0, 0);
        b9.setText("Edit");
        b9.setTextColor(Color.RED);
        b9.setTextSize(15);
        tr.addView(b9);


        table.addView(tr);

        final View vline = new View(Edit.this);
        vline.setLayoutParams(new       
        TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 2));
        vline.setBackgroundColor(Color.RED);
        table.addView(vline); 
        flag=0;
   }

    com.eyal.sms.db.SMS sms;        
    for(int i=0; i<allSched.size(); i++) {

        tr = new TableRow(Edit.this);
        tr.removeAllViewsInLayout();

        sms = allSched.get(i);

        TextView b = new TextView(Edit.this);
        String str = String.valueOf(sms.getToContact());
        b.setText(str != null ? str : "");
        b.setTextColor(Color.WHITE);
        b.setTextSize(15);
        tr.addView(b);

        TextView b1=new TextView(Edit.this);
        b1.setPadding(10, 0, 0, 0);
        b1.setTextSize(15);
        String str1 = sms.getText();
        if (str1.length() > 20) 
            str1 = str1.substring(0, 20); 

        b1.setText(str1);
        b1.setTextColor(Color.WHITE);
        tr.addView(b1);

        TextView b2 = new TextView(Edit.this);
        b2.setPadding(10, 0, 0, 0);
        String str2 = String.valueOf(sms.getToNumber());
        b2.setText(str2);
        b2.setTextColor(Color.WHITE);
        b2.setTextSize(15);
        tr.addView(b2);

        TextView b3 = new TextView(Edit.this);
        b3.setPadding(10, 0, 0, 0);
        String str3 = String.valueOf(sms.getTime());
        b3.setText(str3);
        b3.setTextColor(Color.WHITE);
        b3.setTextSize(15);
        tr.addView(b3);


        Button delete = new Button(Edit.this);
        delete.setText("Delete");            
        DeleteButtonListener dbl = new DeleteButtonListener();
        dbl.setSMS(sms);
        delete.setOnClickListener(dbl);            
        tr.addView(delete);

        Button edit = new Button(Edit.this);
        edit.setText("Edit");
        EditButtonListener ebl = new EditButtonListener();
        ebl.setSMS(sms);
        edit.setOnClickListener(ebl);
        tr.addView(edit);

        table.addView(tr);


        final View vline1 = new View(Edit.this);
        vline1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, 1));
        vline1.setBackgroundColor(Color.WHITE);
        table.addView(vline1);  // add line below each row  

    }
table=(TableLayout)findviewbyd(R.id.cancelTable);
table.removeAllViewsInLayout();
TableRow tr=新的TableRow(编辑.this);
tr.removeAllViewsInLayout();
int标志=1;
如果(标志==1){
TextView b11=新的TextView(编辑.this);
b11.setText(“名称”);
b11.SettexColor(颜色为红色);
b11.SettexSize(15);
tr.addView(b11);
TextView b4=新的TextView(编辑.this);
b4.设置填充(10,0,0,0);
b4.尺寸(15);
b4.setText(“文本”);
b4.setTextColor(颜色为红色);
tr.addView(b4);
TextView b5=新的TextView(编辑.this);
b5.设置填充(10,0,0,0);
b5.setText(“编号”);
b5.setTextColor(颜色为红色);
b5.setTextSize(15);
tr.addView(b5);
TextView b7=新的TextView(编辑.this);
b7.设置填充(10,0,0,0);
b7.setText(“时间”);
b7.setTextColor(颜色为红色);
b7.setTextSize(15);
tr.addView(b7);
TextView b8=新的TextView(编辑.this);
b8.设置填充(10,0,0,0);
b8.setText(“删除”);
b8.setTextColor(颜色为红色);
b8.setTextSize(15);
tr.addView(b8);
TextView b9=新的TextView(编辑.this);
b9.设置填充(10,0,0,0);
b9.setText(“编辑”);
b9.setTextColor(颜色为红色);
b9.setTextSize(15);
tr.addView(b9);
表1.addView(tr);
最终视图线=新视图(编辑此);
vline.setLayoutParams(新
TableRow.LayoutParams(TableRow.LayoutParams.FILL_父项,2));
vline.setBackgroundColor(颜色:红色);
表1.addView(vline);
flag=0;
}
com.eyal.sms.db.sms;
对于(int i=0;i 20)
str1=str1.子串(0,20);
b1.setText(str1);
b1.setTextColor(颜色为白色);
tr.addView(b1);
TextView b2=新的TextView(编辑.this);
b2.设置填充(10,0,0,0);
String str2=String.valueOf(sms.getToNumber());
b2.setText(str2);
b2.setTextColor(颜色为白色);
b2.尺寸(15);
tr.addView(b2);
TextView b3=新的TextView(编辑.this);
b3.设置填充(10,0,0,0);
String str3=String.valueOf(sms.getTime());
b3.setText(str3);
b3.setTextColor(颜色为白色);
b3.setTextSize(15);
tr.addView(b3);
按钮删除=新建按钮(编辑此按钮);
删除.setText(“删除”);
DeleteButtonListener dbl=新的DeleteButtonListener();
dbl.setSMS(sms);
delete.setOnClickListener(dbl);
tr.addView(删除);
按钮编辑=新按钮(编辑此按钮);
edit.setText(“编辑”);
EditButtonListener ebl=新的EditButtonListener();
ebl.SETMS(sms);
edit.setOnClickListener(ebl);
tr.addView(编辑);
表1.addView(tr);
最终视图vline1=新视图(编辑此);
vline1.setLayoutParams(新的TableRow.LayoutParams(TableRow.LayoutParams.WRAP_内容,1));
vline1.setBackgroundColor(颜色:白色);
表.addView(vline1);//在每行下方添加行
}

我错过了什么?RelativeLayout——或者Android中的任何其他布局——可以保证我所有的小部件都在屏幕上,或者至少在所有大小的硬件中都可以滚动吗

试试这个,它将包装您的桌面布局,并修复您的问题

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <TableLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/cancelTable"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_below="@+id/pageheader" >

            </TableLayout>
        </LinearLayout>
    </HorizontalScrollView>

</RelativeLayout>

[编辑1]

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends Activity {
    TableLayout table;
    TableRow tr;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        table = (TableLayout) findViewById(R.id.cancelTable);
        table.removeAllViewsInLayout();
        tr = new TableRow(MainActivity.this);
        int flag = 1;       
        if(flag == 1) {
            TextView b11=new TextView(MainActivity.this);
            b11.setText("Name");
            b11.setTextColor(Color.RED);
            b11.setTextSize(15);
            tr.addView(b11);

            TextView b4 = new TextView(MainActivity.this);
            b4.setPadding(10, 0, 0, 0);
            b4.setTextSize(15);
            b4.setText("Text");
            b4.setTextColor(Color.RED);
            tr.addView(b4);

            TextView b5=new TextView(MainActivity.this);
            b5.setPadding(10, 0, 0, 0);
            b5.setText("Number");
            b5.setTextColor(Color.RED);
            b5.setTextSize(15);
            tr.addView(b5);

            TextView b7=new TextView(MainActivity.this);
            b7.setPadding(10, 0, 0, 0);
            b7.setText("Time");
            b7.setTextColor(Color.RED);
            b7.setTextSize(15);
            tr.addView(b7);

            TextView b8=new TextView(MainActivity.this);
            b8.setPadding(10, 0, 0, 0);
            b8.setText("Delete");
            b8.setTextColor(Color.RED);
            b8.setTextSize(15);
            tr.addView(b8);

            TextView b9=new TextView(MainActivity.this);
            b9.setPadding(10, 0, 0, 0);
            b9.setText("Edit");
            b9.setTextColor(Color.RED);
            b9.setTextSize(15);
            tr.addView(b9);


            table.addView(tr);

            flag=0;
       }

        for(int i=0; i<30; i++) {
            tr = new TableRow(MainActivity.this);

            TextView b = new TextView(MainActivity.this);
            b.setText("TExt");
            b.setTextColor(Color.WHITE);
            b.setTextSize(15);
            tr.addView(b);

            TextView b1=new TextView(MainActivity.this);
            b1.setPadding(10, 0, 0, 0);
            b1.setTextSize(15);
            b1.setText("text2");
            b1.setTextColor(Color.WHITE);
            tr.addView(b1);

            TextView b2 = new TextView(MainActivity.this);
            b2.setPadding(10, 0, 0, 0);
            b2.setText("text3");
            b2.setTextColor(Color.WHITE);
            b2.setTextSize(15);
            tr.addView(b2);

            TextView b3 = new TextView(MainActivity.this);
            b3.setPadding(10, 0, 0, 0);
            b3.setText("text4");
            b3.setTextColor(Color.WHITE);
            b3.setTextSize(15);
            tr.addView(b3);


            Button delete = new Button(MainActivity.this);
            delete.setText("Delete");            
            tr.addView(delete);

            Button MainActivity = new Button(MainActivity.this);
            MainActivity.setText("MainActivity");            
            tr.addView(MainActivity);

            table.addView(tr);

        }

    }  
}
导入android.app.Activity;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.widget.Button;
导入android.widget.TableLayout;
导入android.widget.TableRow;
导入android.widget.TextView;
公共类MainActivity扩展了活动{
表格布局表;
TableRow tr;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
table=(TableLayout)findviewbyd(R.id.cancelTable);
table.removeAllViewsInLayout();
tr=新表行(MainActivity.this);
int标志=1;
如果(标志==1){
TextView b11=新的TextView(MainActivity.this);
b11.setText(“名称”);
b11.SettexColor(颜色为红色);
b11.SettexSize(15);
tr.addView(b11);
TextView b4=新的TextView(MainActivity.this);
b4.设置填充(10,0,0,0);
b4.尺寸(15);
b4.setText(“文本”);
b4.setTextColor(颜色为红色);
tr.addView(b4);
TextView b5=新的TextView(MainActivity.this);
b5.设置填充(10,0,0,0);
b5.setText(“编号”);
b5.setTextColor(颜色为红色);
b5.setTextSize(15);
tr.addView(b5);
TextView b7=新的TextView(MainActivity.this);
b7.设置填充(10,0,0,0);
b7.setText(“时间”);
b7.setTextColor(颜色为红色);
b7.setTextSize(15);
tr.addView(b7);
TextView b8=新的TextView(MainActivity.this);
b8.设置填充(10,0,0,0);
b8.setText(“删除”);
b8.setTextColor(颜色为红色);
b8.setTextSize(15);
tr.addView(b8);
TextView b9=新的TextView(MainActivi