Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.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中,如何在一个表视图中的单个单元格中包装多个文本视图_Android_Android Layout_Android Linearlayout_Android Tablelayout - Fatal编程技术网

在Android中,如何在一个表视图中的单个单元格中包装多个文本视图

在Android中,如何在一个表视图中的单个单元格中包装多个文本视图,android,android-layout,android-linearlayout,android-tablelayout,Android,Android Layout,Android Linearlayout,Android Tablelayout,我需要将一系列文本视图包装在表的单个单元格中,但我无法确定如何使文本视图保留在一个单元格中并根据整个文本视图是否适合同一行进行包装。每个类别名称都是指向另一个活动的链接,每个事件文本视图都是指向另一个活动的链接。此表也是动态构建的,因此可能会提供一些限制 下面是我试图制作的一个测试布局,以确定需要设置哪些设置 <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:lay

我需要将一系列文本视图包装在表的单个单元格中,但我无法确定如何使文本视图保留在一个单元格中并根据整个文本视图是否适合同一行进行包装。每个类别名称都是指向另一个活动的链接,每个事件文本视图都是指向另一个活动的链接。此表也是动态构建的,因此可能会提供一些限制

下面是我试图制作的一个测试布局,以确定需要设置哪些设置

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

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Category"
            android:id="@+id/textView3" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Events"
            android:id="@+id/textView4" />
    </TableRow>

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="A"
            android:id="@+id/textView5" />

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Event 1"
                android:id="@+id/textView6" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text=", Event 2"
                android:id="@+id/textView7" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:id="@+id/textView8"
                android:text=", Event 3" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text=", Event 4"
                android:id="@+id/textView9" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text=", Event 5"
                android:id="@+id/textView12"
                android:singleLine="true" />
        </TableRow>
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="B"
            android:id="@+id/textView10" />

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Event 1"
                android:id="@+id/textView11" />
        </TableRow>
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="C"
            android:id="@+id/textView"
             />

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tableRow">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Event 1"
                android:id="@+id/textView2" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text=", Event 2"
                android:id="@+id/textView13" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:id="@+id/textView14"
                android:text=", Event 3"
                android:singleLine="false" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text=", Event 4"
                android:id="@+id/textView15" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text=", Event 5"
                android:id="@+id/textView16"
                android:singleLine="true" />
        </TableRow>
    </TableRow>

</TableLayout>

更新:

经过一周的摆弄,我仍然无法正确显示我的桌子。我正在正确地解析出我所有的喷发,但当单个间歇泉的喷发次数超过该条线的喷发次数时,仍然无法让它们像在我们的网页上那样换行。下面是我们在web界面上使用的表的链接(如果您更改浏览器大小,您将了解我使用android应用程序的目的)。下面是我的代码,用于构建当前应用程序的表

List<Eruption> alleruptionssum = null;
    try {
        alleruptionssum = db.getDaySummary(CurDateStr);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    String GeyserOLD = "";
    String timeSTR = "";
    long GeyserIDOLD = 0;
    long numEruptions = 0;
    if (alleruptionssum != null) {
        if(alleruptionssum.size() !=0){
            for (Eruption eruption : alleruptionssum) {
                int Live;
                long GeyserID;
                long EruptionID;
                long EruptionUnixTime;
                long EruptionUnixTimeMilli;
                String EruptionRegTime;
                String EruptionTimeDisplay;
                String TimeInfo;
                String Geyser;

                Live = eruption.getLive();
                GeyserID = eruption.getGeyserID();
                EruptionID = eruption.getId();
                Geyser = eruption.getGeyser();
                EruptionUnixTime = eruption.getEruptionUnixtimeTime();
                EruptionUnixTimeMilli = EruptionUnixTime * 1000;
                Date EruptionDate = new Date(EruptionUnixTimeMilli);
                SimpleDateFormat EruptionTimeFormatter = new SimpleDateFormat("HHmm");
                EruptionTimeFormatter.setTimeZone(TimeZone.getTimeZone("US/Mountain"));
                EruptionRegTime = EruptionTimeFormatter.format(EruptionDate);

                TimeInfo = eruption.getTimeInfo();
                EruptionTimeDisplay = EruptionRegTime + TimeInfo;


                if(!GeyserOLD.equals(Geyser)){
                    TableRow trGeyser = new TableRow(this);
                    //Set geyser text
                    TextView tvGeyser = new TextView(this);
                    tvGeyser.setPaintFlags(tvGeyser.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
                    tvGeyser.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
                    tvGeyser.setTextColor(Color.parseColor("#0000EE"));
                    tvGeyser.setBackgroundResource(R.drawable.cell_left_middle);
                    tvGeyser.setPadding(4, 2, 4, 2);
                    tvGeyser.setText(GeyserOLD);
                    final long finalGeyserID = GeyserIDOLD;
                    tvGeyser.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Log.d("GeyserID", String.valueOf(finalGeyserID));
                            link_recent_geyser_info(finalGeyserID);
                        }
                    });
                    trGeyser.addView(tvGeyser);

                    if(!timeSTR.equals("")){
                        LinearLayout llEruptions = new LinearLayout(this);
                        llEruptions.setBackgroundResource(R.drawable.cell_right_middle);
                        llEruptions.setPadding(4,2,4,2);
                        String[] eruptions = timeSTR.split(";");
                        for ( long j = 0; j < numEruptions; j++ ) {
                            String[] ParsedEruptions = eruptions[(int) j].split(",");
                            long PostErupionID = Long.parseLong(ParsedEruptions[0]);
                            String PostEruptionDisplay = ParsedEruptions[1];
                            int PostLive = Integer.parseInt(ParsedEruptions[2]);
                            TextView comma = new TextView(this);
                            comma.setText(", ");
                            comma.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
                            if(j != 0){
                                llEruptions.addView(comma);
                            }
                            TextView tvTime = new TextView(this);
                            tvTime.setText(PostEruptionDisplay);
                            tvTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
                            tvTime.setPaintFlags(tvTime.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
                            if(PostLive == 0){
                                tvTime.setTypeface(null, Typeface.ITALIC);
                                tvTime.setTextColor(Color.parseColor("#FFBD00"));
                            }else{
                                tvTime.setTextColor(Color.parseColor("#0000EE"));
                            }
                            final long finalEruptionID = PostErupionID;
                            tvTime.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Log.d("EruptionID", String.valueOf(finalEruptionID));
                                    link_eruption_detail(finalEruptionID);
                                }
                            });
                            llEruptions.addView(tvTime);
                        }
                        trGeyser.addView(llEruptions);
                        SummaryDataView.addView(trGeyser);
                    }
                    GeyserOLD = Geyser;
                    GeyserIDOLD = GeyserID;

                    timeSTR = EruptionID+","+EruptionTimeDisplay+","+Live;
                    numEruptions = 1;

                }else{
                    //add 1 to eruption counter for current geyser and add the eruption to the string
                    numEruptions = numEruptions+1;
                    timeSTR = timeSTR + ";" + EruptionID+","+      EruptionTimeDisplay+","+Live;
                }
            }
            TableRow trGeyser = new TableRow(this);
            //Set geyser text
            TextView tvGeyser = new TextView(this);
            tvGeyser.setTextColor(Color.parseColor("#0000EE"));
            tvGeyser.setBackgroundResource(R.drawable.cell_left_bottom);
            tvGeyser.setPadding(4, 2, 4, 2);
            tvGeyser.setPaintFlags(tvGeyser.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
            tvGeyser.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
            tvGeyser.setText(GeyserOLD);
            trGeyser.addView(tvGeyser);

            LinearLayout llEruptions = new LinearLayout(this);

            llEruptions.setBackgroundResource(R.drawable.cell_right_bottom);
            llEruptions.setPadding(4,2,4,2);
            String[] eruptions = timeSTR.split(";");
            for ( long j = 0; j < numEruptions; j++ ) {
                String[] ParsedEruptions = eruptions[(int) j].split(",");
                long PostErupionID = Long.parseLong(ParsedEruptions[0]);
                String PostEruptionDisplay = ParsedEruptions[1];
                int PostLive = Integer.parseInt(ParsedEruptions[2]);
               //add comma between eruptions
                TextView comma = new TextView(this);
                comma.setText(", ");
                comma.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
                if(j != 0){
                    llEruptions.addView(comma);
                }
                TextView tvTime = new TextView(this);
                tvTime.setText(PostEruptionDisplay);
                tvTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
                if(PostLive == 0){
                    tvTime.setTypeface(null, Typeface.ITALIC);
                    tvTime.setTextColor(Color.parseColor("#FFBD00"));
                }
                final long finalEruptionID = PostErupionID;
                tvTime.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        link_eruption_detail(finalEruptionID);
                    }
                });
                llEruptions.addView(tvTime);
            }
            trGeyser.addView(llEruptions);
            SummaryDataView.addView(trGeyser);
        }
    }
List allerruptionsum=null;
试一试{
AlleRuptionSum=db.getDaySummmary(CurDateStr);
}捕获(解析异常){
e、 printStackTrace();
}
字符串GeyserOLD=“”;
字符串timeSTR=“”;
长间歇泉=0;
长数值=0;
if(alleruptionssum!=null){
如果(alleruptionssum.size()!=0){
对于(喷发:alleruptionssum){
int Live;
长间歇泉;
长喷发体;
长时间喷发;
长时间喷发;
弦爆发时间;
字符串爆发时间显示;
字符串时间信息;
弦式间歇泉;
Live=喷发。getLive();
GeyserID=喷发。getGeyserID();
explorationId=exploration.getId();
Geyser=喷发。getGeyser();
explorationunixtime=exploration.getexplorationunixtime();
explorationunixtimemilli=explorationunixtime*1000;
日期喷发日期=新日期(喷发unixtimemilli);
SimpleDateFormat ExplorationTimeFormatter=新的SimpleDateFormat(“HHmm”);
expreationTimeFormatter.setTimeZone(TimeZone.getTimeZone(“美国/山区”));
explorationregtime=explorationtimeformatter.format(explorationdate);
TimeInfo=expreation.getTimeInfo();
explorationtimedisplay=explorationregtime+TimeInfo;
如果(!间歇泉等于(间歇泉)){
TableRow trGeyser=新的TableRow(本);
//设置间歇泉文本
TextView tvGeyser=新的TextView(此);
tvGeyser.setPaintFlags(tvGeyser.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG);
tvGeyser.SettexSize(TypedValue.COMPLEX单位倾角,20);
tvGeyser.setTextColor(Color.parseColor(#0000EE));
tvGeyser.setBackgroundResource(R.drawable.cell_left_middle);
设置填充(4,2,4,2);
tvGeyser.setText(间歇泉);
最终长最终序列=间歇泉;
tvGeyser.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Log.d(“GeyserID”,String.valueOf(finalGeyserID));
链接最近的间歇泉信息(最终版本);
}
});
trGeyser.addView(tvGeyser);
如果(!timeSTR.equals(“”){
LinearLayout Lleroutions=新的LinearLayout(本);
l破裂。挫折背景资源(R.可绘制。单元格右\中);
l破裂。设置填充(4,2,4,2);
String[]expreations=timeSTR.split(“;”);
对于(长j=0;j<数值;j++){
字符串[]ParsedEruptions=expreations[(int)j].split(“,”;
long PostErupionID=long.parseLong(ParsedEruptions[0]);
字符串postExplorationDisplay=ParsedEruptions[1];
int PostLive=Integer.parseInt(ParsedEruptions[2]);
TextView逗号=新的TextView(此);
逗号.setText(“,”);
逗号.setTextSize(TypedValue.COMPLEX\u UNIT\u DIP,20);
如果(j!=0){
l中断。添加视图(逗号);
}
TextView tvTime=新的TextView(此);
tvTime.setText(喷发后显示);
tvTime.setTextSize(TypedValue.COMPLEX\u UNIT\u DIP,20);
tvTime.setPaintFlags(tvTime.getPaintFlags()|绘制.下划线_文本_标志);
如果(PostLive==0){
设置字体(null,Typeface.ITALIC);
tvTime.setTextColor(Color.parseColor(#FFBD00”);
}否则{
tvTime.setTextColor(Color.parseColor(#0000EE));
}
最终长finalReportionId=PostErupionID;
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共空间