小编Jac*_*ack的帖子

是否可以使线性布局可滚动?

我创建了一个垂直线性布局并在其中放置了许多项目,并且只有部分项目可以显示在屏幕上.我可以看到布局的前几个项目,但无法看到布局的最后几个项目.如何使线性布局可滚动,以便用户可以滚动屏幕以查看线性布局的最后几项?以下是布局xml文件的内容:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView_gridw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Grid Width"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_gridw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView_gridh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Height"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_gridh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

        <TextView
            android:id="@+id/textView_gridbt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Border thickness"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_gridborderthickness"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

        </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView_bgw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="BgImg Width" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

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

C++:由于函数返回的类引用,构造函数和析构函数不成对出现

众所周知,构造函数和析构函数成对出现.

但是下面的代码不是这样的,构造函数被调用两次但是析构函数只被调用一次!

{
    Animal ahe;
    ahe = CreateAnimal();
}
Run Code Online (Sandbox Code Playgroud)

请继续阅读以获得更详细的解释.

假设有一个名为Animal的类,我们有以下代码:

int main(int argc, char* argv[])
{
    Animal ahe;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

预计Animal的构造函数和析构函数都将被调用一次且仅被调用一次.当我运行代码时,它的行为完全符合我的预期.

但是当涉及到一个函数返回Animal的引用时,它看起来很奇怪.当我运行代码时,构造函数被调用两次,但析构函数只被调用一次!

#include "stdafx.h"
#include "stdio.h"
#include "iostream.h"

class Animal
{
public:
    Animal();
    Animal(long age);

    ~Animal();
private:
    long m_age;
};

Animal::~Animal()
{
    cout<<"Animal::~Animal()"<<"age="<<m_age<<endl;
}
Animal::Animal()
{
    m_age = 1;
    cout<<"Animal::Animal()"<<"age="<<m_age<<endl;
}

Animal::Animal(long age)
{
    m_age = age;
    cout<<"Animal::Animal()"<<"age="<<m_age<<endl;
}

Animal& CreateAnimal()
{
    Animal *pAnimal = new Animal(5);

    return *pAnimal;
}

int main(int argc, char* argv[])
{
    Animal ahe; …
Run Code Online (Sandbox Code Playgroud)

c++

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

标签 统计

android ×1

android-layout ×1

c++ ×1