小编Jai*_*ena的帖子

ExpandableListView可扩展列表的高度为wrap_content,且高度低于它时不扩展

这是我的布局代码。当我单击可扩展列表视图时,它不会扩展。但是,如果我增加列表的高度,它将扩展。有没有办法通过代码动态增加列表的高度?我可以在布局的中间进行扩展吗?因为如果我增加高度,它只会在折叠列表中添加不必要的空白。

码:

<ScrollView 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">

    <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.pocketcash.pocketcash.HomeActivity">

        <Switch
            android:id="@+id/detailedCashInfoSwitch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:onClick="cashToggleSwitchClicked"
            android:text="Toggle Detailed Cash Info" />

        <Button
            android:id="@+id/addCashButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/expandableListView2"
            android:layout_centerHorizontal="true"
            android:onClick="launchAddCash"
            android:text="Add cash" />

        <Button
            android:id="@+id/addExpenditureButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/addCashButton"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="25dp"
            android:onClick="launchAddExpenditure"
            android:text="Add expenditure" />

        <TextView
            android:id="@+id/recentLogsText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/addExpenditureButton"
            android:layout_marginTop="50dp"
            android:text="Recent Logs:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/logText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/recentLogsText"
            android:layout_marginTop="0dp"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/recentViewAllText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/recentLogsText" …
Run Code Online (Sandbox Code Playgroud)

xml android expandablelistview android-studio android-wrap-content

6
推荐指数
1
解决办法
7443
查看次数

我的 homeAsUp 按钮在 android 中不起作用

我创建了一个导航抽屉活动,从主要活动中我启动了 2 个不同的活动。在这两个活动中,我都使用了 actionBar.setDisplayHomeAsUpEnabled(true); 启用 homeasup 按钮。我如何找到这些主页按钮的 ID,以便我可以在 onOptionsItemSelected 中使用它们?这是我的方法:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            Toast.makeText(this, "pressed1", Toast.LENGTH_SHORT).show();
            return true;
        }
        else if (id == R.id.home){
            Toast.makeText(this,"pressed2",Toast.LENGTH_SHORT).show();
            finish();
        }
        else{
            Toast.makeText(this,R.id.homeAsUp + " " + id + " …
Run Code Online (Sandbox Code Playgroud)

android android-studio navigation-drawer

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