小编Mar*_*one的帖子

当ListView的大小发生变化时,保持ListView的最后一个可见项

我想要的很简单,至少我认为这很简单.我只想要一个窗口,其中EditText位于屏幕的底部,其余的空间用ListView填充.不幸的是,它没有像我预期的那样工作.我想要的是下图.有没有简单的方法在XML中执行此操作,还是应该为此编写一些特殊代码? 我想要的是

我有问题的Android源代码.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
    android:id="@+id/demolist"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
     >
</ListView>
    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_weight="0">
    </EditText>
</LinearLayout >
Run Code Online (Sandbox Code Playgroud)

layout android listview

31
推荐指数
2
解决办法
2万
查看次数

为现有缓冲区提供std :: istream接口而不复制它

我有一个固定长度的字符缓冲区,我想将它提供给一个带有std :: istream&的函数.如何在不复制缓冲区的情况下执行此操作?

如果这意味着派生出一个自定义的streambuf,我想我会接受这个副本.我只是想知道我是否错过了一些直截了当的东西.

这就是我现在正在做的事情(这是不需要的副本):

void loadFromBuffer(const char* buff, size_t len) {
    std::istringstream is(std::string(buff, len)); // BUFFER COPIED HERE :(
    load(is);
}
Run Code Online (Sandbox Code Playgroud)

编辑:

为了记录,这是使用boost.Iostreams的简单解决方案:

#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/stream.hpp>

void loadFromBuffer2(char* buff, size_t len) {
    typedef boost::iostreams::stream<boost::iostreams::array_source> array_stream;
    array_stream is(buff, len);
    load(is);
}
Run Code Online (Sandbox Code Playgroud)

我接受了Boost.Iostreams的答案,因为它似乎是"正确的"解决方案,但它不能在我的平台(Android NDK)上编译,所以我最终使用了弃用的std :: istrstream解决方案.感谢大家.

c++ iostream

11
推荐指数
1
解决办法
4219
查看次数

使用appcompat和工具栏时,为什么我的自定义操作栏视图"匹配父级"?

我正在操作栏中设置自定义视图.使用SDK操作栏时,它会填充操作栏的宽度,但在使用appcompat版本时则不会.使用appcompat和Toolbar时,为什么我的线性布局不会填充宽度?我能做些什么呢?

这是pre-appcompat的样子:

在此输入图像描述

这就是appcompat的样子.(红色显示我的自定义视图的范围.):

在此输入图像描述

编辑:这是使用@Seidan的显式布局参数提示的样子.(显示应该是白色的黑色文字):

在此输入图像描述

这是我的自定义布局:

<?xml version="1.0" encoding="utf-8"?>
<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="horizontal"
    android:background="#800"
    >

    <FrameLayout
        android:id="@+id/actionbar_discard"
        style="?attr/actionButtonStyle"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        >

        <TextView
            style="?android:actionBarTabTextStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:drawableLeft="@drawable/ic_close_white_24dp"
            android:drawablePadding="8dp"
            android:gravity="center_vertical"
            android:paddingRight="20dp"
            android:text="@string/actionbar_cancel" />
    </FrameLayout>

    <FrameLayout
        android:id="@+id/actionbar_done"
        style="?attr/actionButtonStyle"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <TextView
            style="?android:actionBarTabTextStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:drawableLeft="@drawable/ic_check_white_24dp"
            android:drawablePadding="8dp"
            android:gravity="center_vertical"
            android:paddingRight="20dp"
            android:text="@string/actionbar_done" />
    </FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

以下是我设置操作栏的方法:

ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayOptions(
        ActionBar.DISPLAY_SHOW_CUSTOM,
        ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
ab.setCustomView(R.layout.actionbar_discard_done);
Run Code Online (Sandbox Code Playgroud)

appcompat-v7:22.0.0和新的appcompat-v7:22.1.0都出现此问题.

android android-appcompat material-design

7
推荐指数
1
解决办法
3658
查看次数

Android上的Kotlin:将光标映射到列表

在Kotlin中,迭代Android Cursor对象并将结果放入列表的最佳方法是什么?

我自动转换的Java:

val list = ArrayList<String>()
while (c.moveToNext()) {
    list.add(getStringFromCursor(c))
}
Run Code Online (Sandbox Code Playgroud)

有更惯用的方式吗?特别是,它可以在一个只读列表的单一分配中完成吗?例如...

val list = /*mystery*/.map(getStringFromCursor)
Run Code Online (Sandbox Code Playgroud)

......或其他一些安排,其中列表是完整的.

android functional-programming kotlin

7
推荐指数
1
解决办法
4231
查看次数