扩展Android ViewGroup类时,onLayout()覆盖的目的是什么?我在Android中进行自定义控件但由于某种原因,内容(子View对象)没有显示.我的方法是扩展ViewGroup类,通过addView()ViewGroup 的方法添加子视图.然后,在我的主要活动中,我有以下代码:
ChannelController myCC = new ChannelController(this);
setContentView(myCC);
Run Code Online (Sandbox Code Playgroud)
ChannelController是我的自定义类的名称,它扩展了ViewGroup.我必须做错事,因为屏幕上没有显示任何内容.
我知道我必须覆盖并实现onLayout()方法,但是用什么?我知道在dev.android网站上有一整页专门用于此,但它对我没有多大帮助,主要是因为我认为我是新手.任何见解将不胜感激.
作为参考,我的ViewGroup扩展如下所示:
public class ChannelController extends ViewGroup {
final String TAG = "JAL";
public ChannelController(Context c)
{
super(c);
init(c);
}
public ChannelController(Context c, AttributeSet attibset)
{
super(c);
init(c);
}
public ChannelController(Context c, AttributeSet attribset, int defStyle)
{
super(c);
init(c);
}
public void init(Context c)
{
//RelativeLayout wrap = new RelativeLayout(c);
RelativeLayout.LayoutParams wrapLP = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout r1 = new RelativeLayout(c);
RelativeLayout.LayoutParams r1LP …Run Code Online (Sandbox Code Playgroud) 我必须对C++ 11有一个基本的误解.我的教授告诉我,除了引用或指针之外,不可能将非原始类型传递给函数.但是,以下代码工作得很好
#include <iostream>
using namespace std;
class MyClass
{
public:
int field1;
};
void print_string(string s) {
cout << s << endl;
}
void print_myclass(MyClass c) {
cout << c.field1 << endl;
}
int main(int argc, char *argv[])
{
string mystr("this is my string");
print_string(mystr); // works
MyClass m;
m.field1=9;
print_myclass(m);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
运行该程序会产生以下输出
this is my string
9
RUN SUCCESSFUL (total time: 67ms)
Run Code Online (Sandbox Code Playgroud)
我在Win7上使用MinGW/g ++
为什么这样做?我以为非原始类型不能通过值传递?!
我正在使用一个java.util.concurrent.ConcurrentLinkedQueue对象在线程之间传递数据.
我应该申报我的推荐信volatile吗?
我在Eclipse中有两个C ++项目,“ amp”和“ amp_auditions”
第一个创建一个库, C:\Users\Jared\EclipseWorkspace\amp\Debug\libamp.dll
第二个程序是测试程序('C:\Users\Jared\EclipseWorkspace\amp_auditions'),它依赖于第一个程序,并C:\Users\Jared\EclipseWorkspace\amp\Debug在“项目属性”>“库依赖项”下列出了目录。
要使用我创建的amp库,我以为我需要做的就是链接库文件并包含标头,但显然并不是那么简单。
一切都能编译,但是当我调试时,应用程序立即终止。GDB跟踪告诉我:
488,262 19^error,msg="During startup program exited with code 0xc0000135."
Run Code Online (Sandbox Code Playgroud)
如果我直接在终端中运行测试程序,它将抱怨缺少依赖项。 如果我将libamp.dll文件放在C:\Users\Jared\EclipseWorkspace\amp_auditions目录中,则一切正常。这告诉我调试器找不到问题libamp.dll
我错过了什么?为什么我的测试程序不能在Eclipse调试透视图中运行?
海湾合作委员会-v
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)
Run Code Online (Sandbox Code Playgroud)
gdb跟踪:
487,988 2-environment-cd C:/Users/Jared/EclipseWorkspace/amp_auditions
487,991 2^done
487,991 (gdb)
487,991 3-gdb-set breakpoint pending on
487,991 3^done
487,991 (gdb)
487,992 4-gdb-set detach-on-fork on
487,992 4^done
487,992 (gdb) …Run Code Online (Sandbox Code Playgroud) c++ ×2
android ×1
android-view ×1
class ×1
concurrency ×1
dll ×1
eclipse ×1
eclipse-cdt ×1
java ×1
volatile ×1