我在Fragment中为动态创建的自定义列表视图的元素设置相等的宽度空间时出现问题。所有元素都排列在同一列表视图中。请介绍如何在自定义视图中使其全部独一无二。请参阅此图片。帮我。在此先感谢!!!!
代码------>
<DockPanel>
<JavaScript>
var Observable = require("FuseJS/Observable");
var data = Observable();
fetch('https://localhost:8080/graphql', {
"method": 'POST',
"headers": { "Content-type": "application/graphql", "Accept": "application/json"},
"body": {"query": "{ places { id name address city }" }
})
.then(function(response) { return response.json; })
.then(function(responseObject) { data.value = responseObject; });
module.exports = {
dataSource: data
};
</JavaScript>
<StatusBarBackground Dock="Top" />
<BottomFrameBackground Dock="Bottom" />
<StackPanel Dock="Top">
<Text FontSize="28" Alignment="VerticalCenter"
TextAlignment="Center" Padding="2"
Value="NEWS" />
<Rectangle Height="1" Margin="0,3,0,0" Fill="#333c48" />
</StackPanel>
<Text ux:Class="Header" Margin="10,10,10,5" TextWrapping="Wrap" FontSize="22" />
<Text ux:Class="Article" Margin="10,0,10,0" TextWrapping="Wrap" FontSize="13" />
<Text ux:Class="PublishedDate" Margin="10,0,10,0" FontSize="13" Color="#999" />
<ScrollView>
<StackPanel Alignment="Top">
<Panel Height="7" />
<Each Items="{dataSource.data.places}">
<Panel ux:Class="HorizontalBar" Margin="46,10,0,10"
Alignment="VerticalCenter">
<Rectangle Height="1" Fill="#dcdee3" />
</Panel>
<Header Value="{name}" />
<Article Value="{address}" />
<PublishedDate Value="{city}" />
<HorizontalBar />
</Each>
</StackPanel>
</ScrollView>
</DockPanel>
答案 0 :(得分:0)
我认为使用GridView更好。您没有提供ListView的代码,但我认为TableLayot和TableRow没用。但无论如何你可以尝试将TextViews和Button放在LinearLayout中并给它们一些权重。 例如,给他们相等的空间:
<LinearLayout
android:id="@+id/horizontal_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="20dp"
android:textSize="18sp"
android:textColor="#800080"
android:id="@+id/txt1">
</TextView>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="20dp"
android:textSize="18sp"
android:textColor="#800080"
android:id="@+id/txt2">
</TextView>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="20dp"
android:textSize="18sp"
android:textColor="#800080"
android:id="@+id/txt3">
</TextView>
<Button
android:id="@+id/del_button"
android:text="Delete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:onClick="addItems"
android:layout_gravity="right"
android:theme="@style/MyButton"
android:layout_width="0dp"
android:layout_weight="1"
/>
</LinearLayout>