Listview无法显示最后一项(Listview can't displayed the last item)
我的问题是我无法在列表中显示我的最后一项。 就像被手机切断一样。
这是xml代码:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1"> <RelativeLayout android:orientation="vertical" android:id="@+id/border" android:layout_width="match_parent" android:layout_height="280dp" android:background="@drawable/dfcomment3" android:layout_weight="0.07"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="40dp" android:text="Add comment" android:id="@+id/button12" android:layout_marginTop="215dp" android:layout_marginLeft="5dp" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="40dp" android:text="Update Post" android:id="@+id/button13" android:layout_marginTop="215dp" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="40dp" android:text="Close This" android:id="@+id/button14" android:layout_marginTop="215dp" /> </LinearLayout> <TextView android:layout_marginLeft="10dp" android:textSize="35dp" android:id="@+id/textView11" android:gravity="center" android:text="ID" android:textStyle="bold" android:textColor="#994495" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/textView12" android:text="Name" android:textSize="16dp" android:textColor="#994495" android:layout_marginTop="190dp" android:layout_marginLeft="210dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/textView13" android:text="Lastname" android:textStyle="bold" android:textSize="16dp" android:layout_marginLeft="90dp" android:textColor="#994495" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/id" android:layout_toEndOf="@+id/id" android:layout_marginTop="5dp" /> <TextView android:id="@+id/textView14" android:text="title" android:textSize="15dp" android:textColor="#994495" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="260dp" android:layout_below="@+id/name" android:layout_alignStart="@+id/name" android:layout_marginTop="190dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="descr" android:textSize="21dp" android:textColor="#994495" android:id="@+id/textView15" android:layout_marginLeft="110dp" android:layout_marginTop="60dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="dept" android:textStyle="italic" android:textColor="#994495" android:id="@+id/textView16" android:layout_marginLeft="180dp" android:layout_marginTop="30dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="tags" android:textStyle="italic" android:textSize="14dp" android:textColor="#994495" android:id="@+id/textView17" android:layout_marginLeft="120dp" android:layout_marginTop="30dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="status" android:textSize="25dp" android:textStyle="bold" android:textColor="#70CC86" android:id="@+id/textView18" android:layout_marginLeft="290dp" android:layout_marginTop="10dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="date" android:textColor="#994495" android:id="@+id/textView19" android:layout_marginLeft="10dp" android:layout_marginTop="190dp" /> </RelativeLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="match_parent" > <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </LinearLayout>
我想尽可能地坚持使用listview,因为我不熟悉recyclerview。 如果有任何解决方法,我会很高兴。 检查图像以获取我的问题的参考。
列表中实际上有4个项目,我只能查看2个项目。
This is the my current listivew:
My problem is i can't display my last item in the list. It's like getting cut by my phone.
Here is the xml code:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1"> <RelativeLayout android:orientation="vertical" android:id="@+id/border" android:layout_width="match_parent" android:layout_height="280dp" android:background="@drawable/dfcomment3" android:layout_weight="0.07"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="40dp" android:text="Add comment" android:id="@+id/button12" android:layout_marginTop="215dp" android:layout_marginLeft="5dp" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="40dp" android:text="Update Post" android:id="@+id/button13" android:layout_marginTop="215dp" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="40dp" android:text="Close This" android:id="@+id/button14" android:layout_marginTop="215dp" /> </LinearLayout> <TextView android:layout_marginLeft="10dp" android:textSize="35dp" android:id="@+id/textView11" android:gravity="center" android:text="ID" android:textStyle="bold" android:textColor="#994495" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/textView12" android:text="Name" android:textSize="16dp" android:textColor="#994495" android:layout_marginTop="190dp" android:layout_marginLeft="210dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/textView13" android:text="Lastname" android:textStyle="bold" android:textSize="16dp" android:layout_marginLeft="90dp" android:textColor="#994495" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/id" android:layout_toEndOf="@+id/id" android:layout_marginTop="5dp" /> <TextView android:id="@+id/textView14" android:text="title" android:textSize="15dp" android:textColor="#994495" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="260dp" android:layout_below="@+id/name" android:layout_alignStart="@+id/name" android:layout_marginTop="190dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="descr" android:textSize="21dp" android:textColor="#994495" android:id="@+id/textView15" android:layout_marginLeft="110dp" android:layout_marginTop="60dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="dept" android:textStyle="italic" android:textColor="#994495" android:id="@+id/textView16" android:layout_marginLeft="180dp" android:layout_marginTop="30dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="tags" android:textStyle="italic" android:textSize="14dp" android:textColor="#994495" android:id="@+id/textView17" android:layout_marginLeft="120dp" android:layout_marginTop="30dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="status" android:textSize="25dp" android:textStyle="bold" android:textColor="#70CC86" android:id="@+id/textView18" android:layout_marginLeft="290dp" android:layout_marginTop="10dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="date" android:textColor="#994495" android:id="@+id/textView19" android:layout_marginLeft="10dp" android:layout_marginTop="190dp" /> </RelativeLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="match_parent" > <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </LinearLayout>
As much as possible i want to stick with the listview because i'm not familiar with the recyclerview. if theres any way to fix this, i would be glad. Check the image for the reference of my problem.
There's actually 4 items in the list and i can only view 2 items.
原文:https://stackoverflow.com/questions/43962424
最满意答案
是的,这是一个RDD,而不是一个Python对象,您可以将其排序,就像它是本地集合一样。 但是在
groupByKey()
之后,每个键值元组中的值是一个数字集合,这是你想要排序的吗? 您可以使用mapValues()
sorted()
在其参数上调用sorted()
。我意识到这是一个玩具示例,但要小心
groupByKey
因为它必须获取内存中键的所有值。 此外,甚至不一定能保证具有2个元素的RDD和2个分区,意味着1进入每个分区。 这很可能,但不是讽刺。PS你应该能够用
values()
替换map(lambda x: x[1])
values()
。 它可能更快。Yes, that's an RDD, not a Python object that you can sort as if it's a local collection. After
groupByKey()
though, the value in each key-value tuple is a collection of numbers, and that is what you want to sort? You can usemapValues()
which calledsorted()
on its argument.I realize it's a toy example but be careful with
groupByKey
as it has to get all values for a key in memory. Also it is not even necessarily guaranteed that an RDD with 2 elements, and 2 partitions, means 1 goes in each partition. It's probable but not guarnateed.PS you should be able to replace
map(lambda x: x[1])
withvalues()
. It may be faster.
相关问答
更多-
是的,这是一个RDD,而不是一个Python对象,您可以将其排序,就像它是本地集合一样。 但是在groupByKey()之后,每个键值元组中的值是一个数字集合,这是你想要排序的吗? 您可以使用mapValues() sorted()在其参数上调用sorted() 。 我意识到这是一个玩具示例,但要小心groupByKey因为它必须获取内存中键的所有值。 此外,甚至不一定能保证具有2个元素的RDD和2个分区,意味着1进入每个分区。 这很可能,但不是讽刺。 PS你应该能够用values()替换map(lambd ...
-
groupByKey不知道地图边聚合是否会保存任何内容以及如何去做,因为它没有关于您计划进行聚合的信息(如果有的话)。 reduceByKey或combineByKey提供了一个聚合函数,这意味着spark可以实际做这种优化。 groupByKey doesn't know whether map side aggregations would save anything and how to do them as it has no information on the aggregation you a ...
-
Spark 2.0 DataSets groupByKey并划分操作和类型安全(Spark 2.0 DataSets groupByKey and divide operation and type safety)[2023-08-05]
第一个问题可以通过一直使用类型列来解决( KeyValueGroupedDataset.agg需要TypedColumn(-s) )您可以将聚合结果定义为: val eight = lit(8.0) .as[Double] // Not necessary val sumByEight = typedSum[MyClass](_.c4) .divide(eight) .as[Double] // Required .name("div(sum(c4), 8)") 并将其插入以下代码: ... -
这些迭代是懒惰的,至少在Dataflow运行器上运行时,它们允许每个键保存的数据多于内存中的数据。 当你通过Iterable时,键的值会懒洋洋地加载到内存中。 These iterables are lazy and, at least when running on Dataflow runner, they are allowed to hold more data per key than will fit in memory. Values for the key get loaded into m ...
-
没有。 将RDD中每个键的值分组为单个序列。 使用现有的分区程序/并行级别对生成的RDD进行散列分区。 不保证每个组内元素的排序,并且每次评估结果RDD时甚至可能不同。 https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.rdd.PairRDDFunctions@groupByKey():org.apache.spark.rdd.RDD[(K,Iterable [V])] No. Group the value ...
-
如何在Spark中使用DenseVector作为键将groupByKey组为RDD?(How to groupByKey a RDD, with DenseVector as key, in Spark?)[2023-03-19]
嗯,这是一个棘手的问题,简短的回答是你做不到的。 要理解为什么你必须深入研究DenseVector实现。 DenseVector只是NumPy float64 ndarray的包装器 >>> dv1 = DenseVector([3.0, 4.0]) >>> type(dv1.array)>>> dv1.array.dtype dtype('float64') 由于NumPy ndarrays ,不像DenseVector那样可变,不能以有意义的方式进行散列 ... -
Spark Scala groupByKey和flatMapGroups给出空数据帧(Spark Scala groupByKey and flatMapGroups give empty dataframe)[2022-10-14]
您可以尝试以下代码: val spark = SparkSession.builder .master("local[*]") .appName("testApp") .config("spark.sql.warehouse.dir", "file:///c:/tmp/spark-warehouse") .getOrCreate() import spark.implicits._ val ds = Seq(("99227100", "42222245", "2018-04-26") ... -
如果要缩减为单个元素而不是列表。 例如:像字数一样,那么aggregateByKey表现得更好,因为它不会导致shuffle,正如group by vs aggregate by的链接性能所解释的那样。 但在你的情况下,你正在合并到一个列表。 在aggregateByKey的情况下,它将首先将分区中的键的所有值减少到单个列表,然后发送shuffle数据。这将创建与分区一样多的列表,并且内存将很高。 在groupByKey的情况下,合并仅在负责密钥的一个节点处发生。 创建的列表数量在此处仅为每个键一个。 在合 ...
-
您必须考虑三种类型的操作: 仅使用mapPartitions(WithIndex)实现的转换,如filter , map , flatMap等。通常它将是最安全的组。 可能遇到的最大可能问题是广泛的磁盘溢出。 需要洗牌的转型。 它包括明显的犯罪嫌疑人像combineByKey ( groupByKey , reduceByKey , aggregateByKey )的不同变种或join和不太明显像sortBy , distinct或sortBy 。 如果没有上下文(数据分布,精简函数,分割器,资源),很难判 ...
-
GroupByKey并创建值为pyspark sql dataframe的列表(GroupByKey and create lists of values pyspark sql dataframe)[2023-08-01]
以下是获取该数据框的步骤。 >>> from pyspark.sql import functions as F >>> >>> d = [{'a': 5, 'b': 2, 'c':1}, {'a': 5, 'b': 4, 'c':3}, {'a': 2, 'b': 4, 'c':2}, {'a': 2, 'b': 3,'c':7}] >>> df = spark.createDataFrame(d) >>> df.show() +---+---+---+ | a| b| c| +---+---+-- ...