这让我完全疯了。 我想在android中使用一个有点复杂的布局。我正在尝试使用权重而不是修复事物的大小。也许我应该放弃......
这就是我想要做的事情:
我希望有3个滚动视图(里面有文本视图)和列表视图大小相同。
我使用了一个权重为4的TableLayout,并给出了包含scrollviews和listview的行权重为1.这实际上有点工作,这让我感到惊讶,因为还有其他行没有分配权重。 但是一旦列表视图实际填充或文本视图开始占用多行,一切都搞砸了。我希望他们都保持相同的大小。
我在下面粘贴了我当前的axml文件。我已经尝试了一百万种不同的东西,我准备放弃。这真的不应该那么难。
提前致谢!
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/StepTable"
android:stretchColumns="*"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@color/bgray"
android:padding="15dp"
android:weightSum="4">
<TableRow
style="@style/PhaseHeaderRow">
<TextView
android:text="Header 1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="3"
style="@style/PhaseHeader" />
</TableRow>
<TableRow
style="@style/PhaseRow.ListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="3">
<TextView
android:id="@+id/txt_PhaseListNumber"
android:gravity="center"
android:layout_weight="1"
android:text="Sub"
style="@style/PhaseTextView.List"
android:width="0px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp" />
<TextView
android:id="@+id/txt_PhaseListStatus"
android:layout_weight="2"
android:gravity="center"
style="@style/PhaseTextView.List"
android:width="0px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="head" />
<TextView
android:id="@+id/txt_PhaseListNote"
android:layout_weight="5"
android:gravity="left"
android:text="er"
style="@style/PhaseTextView.List"
android:width="0px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp" />
</LinearLayout>
</TableRow>
<TableRow
android:id="@+id/row_StepList"
android:layout_weight="1"
android:layout_width="fill_parent"
android:background="#ff9abf2f"
android:layout_height="wrap_content">
<ListView
android:id="@+id/list_Steps"
android:layout_span="3"
android:listSelector="#44ff0000"
android:drawSelectorOnTop="true"
android:choiceMode="singleChoice"
android:layout_width="fill_parent" />
</TableRow>
<TableRow
android:id="@+id/row_PhaseDescHeader"
style="@style/PhaseHeaderRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txt_PhaseDescHeader"
style="@style/PhaseHeader"
android:text="Header 2" />
</TableRow>
<TableRow
android:id="@+id/row_TesterActionLabel"
style="@style/PhaseRow.ListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txt_TesterActionLabel"
android:text="SubHeader"
style="@style/PhaseTextView.List"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="@+id/row_TesterAction"
style="@style/PhaseRow"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scroller_TesterAction"
android:layout_weight="1"
android:scrollbars="vertical"
android:fillViewport="true"
android:layout_span="3"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/txt_TesterAction"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="15sp"
android:ellipsize="start"
android:text="ScollView with TextView Inside" />
</ScrollView>
</TableRow>
<TableRow
android:id="@+id/row_ExitCriteraLabel"
style="@style/PhaseRow.ListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txt_ExitCriteraLabel"
android:text="SubHeader"
style="@style/PhaseTextView.List"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="@+id/row_ExitCritera"
style="@style/PhaseRow"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scroller_ExitCritera"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fillViewport="true"
android:layout_span="3">
<TextView
android:id="@+id/txt_ExitCritera"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:ellipsize="start"
android:text="Another ScollView with TextView Inside" />
</ScrollView>
</TableRow>
<TableRow
android:id="@+id/row_PhaseNotesHeader"
style="@style/PhaseHeaderRow">
<TextView
android:id="@+id/txt_PhaseNotesHeader"
style="@style/PhaseHeader"
android:text="Header 3" />
</TableRow>
<!-- -->
<TableRow
android:id="@+id/row_Notes"
style="@style/PhaseRow"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scroller_Notes"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fillViewport="true"
android:layout_span="3">
<TextView
android:id="@+id/txt_Notes"
android:layout_width="fill_parent"
android:textSize="17sp"
android:layout_height="wrap_content"
android:text="Yet another ScollView with TextView Inside"
android:singleLine="false"
android:ellipsize="none" />
</ScrollView>
</TableRow>
</TableLayout>
</TableLayout>
答案 0 :(得分:1)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#a3c3c3"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#B40404"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Header1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F78181"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub3"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/ln1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_weight="1"
android:background="#a3c3c3" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F78181"
android:text="sub Header1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/ln1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_weight="1"
android:background="#a3c3c3" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#a3c3c3"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#B40404"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Header2"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F78181"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub3"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/ln1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/textView1"
android:background="#a3c3c3" android:layout_weight="1">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F78181"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sub2"
android:textAppearance="?android:attr/textAppearanceLarge" android:layout_weight="1"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub3"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/ln1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/textView1"
android:background="#a3c3c3" android:layout_weight="1">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#a3c3c3"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#B40404"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Header3"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F78181"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sub3"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/ln1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:background="#a3c3c3" >
</LinearLayout>
<LinearLayout
android:id="@+id/ln1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_weight="1"
android:background="#a3c3c3" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
答案 1 :(得分:0)
也许你可以使用WebViews而不是TextViews,因为WebViews有自己的滚动功能。
您可以使用以下代码加载数据:
WebView wv = (WebView)findViewById(R.id.webView1);
wv.loadDataWithBaseURL("file:///android_asset/", description, "text/html", "utf-8", null);
另一方面,我会使用具有相同权重的四个RelativeLayouts的垂直LinearLayout,因此它们将使用相同的空间。然后,这些RelativeLayouts中的WebView和ListViews可以将match_parent作为高度。