我有框架布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" >
<LinearLayout
android:id="@+id/widgetView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center" >
</LinearLayout>
<LinearLayout
android:id="@+id/widgetOverlayFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false" >
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
第一个布局包含窗口小部件布局,第二个布局是透明的,并且接收onLongClick用于拖动方法.这有效,问题是当我想要与窗口小部件交互时,点击某些内容,点击事件由overlayFrame拍摄.如何将click事件通过overlayFrame传递给widgetView?
编辑:
现在我正在尝试将GestureLister附加到overlayFrame LinearLayout,以某种方式看到代表单击和长按的MotionEvent之间的区别.我面临的问题是,手势监听器中的OnLongPress总是被调用,无论我做什么,单击还是长按.
这种行为有解释吗?TNX!
如何在edittextpreference对话框中设置null验证,这样如果它为null,则用户不应该单击ok,并且应该在对话框本身中显示一些消息.我一直试图找到它很长一段时间但没有成功......
android preferenceactivity android-alertdialog edittextpreference
如何在后台线程上执行?即使用户按下主页按钮,执行也应在后台继续.
我有一个包含4个嵌套线性布局的linearlayout.我需要隐藏第一个嵌套布局并显示2和3,然后隐藏2和3并显示第1个.我想用滑动效果来动画这些过渡.所以有屏幕的第一张幻灯片,然后是2和3幻灯片.我设法动画1滑动(虽然不是很顺利),但无法弄清楚如何从View.GONE到View.VISIBLE进行滑动.
如果没有动画我只是做setVisiblity 1日将其隐藏,然后setVisiblity的2/3拍他们,那么它是非常出问题和文字重叠.
请参阅下面我遇到的问题.
我用来隐藏/显示的代码:
LinearLayout item2= (LinearLayout) rootView.findViewById(R.id.item2);
LinearLayout item1= (LinearLayout) rootView.findViewById(R.id.item2);
item1.setVisibility(View.GONE);
item2.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)
我有一个只有TextView的ListView.我想要一个实现,如果我单击ListView行,应该出现带有替换按钮的edittext,无论我在该edittext中输入什么,然后单击替换,listrow应该更新.我面临的主要问题是在List行上放置一个布局.任何人都告诉我如何实现这个目标?
public class ContextMenuActivity extends Activity {
private ListView list;
TextView tv;
ArrayList<String> alistItems;
int loopCount;
CustomAdapter adapter;
LayoutInflater inflater;
TextView textView;
EditText edtTextToReplace;
RelativeLayout rl_inflate;
View child;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contextmenulist);
initComponents();
setActionListener();
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Options");
menu.add(0, v.getId(), 0, "Edit");
menu.add(0, v.getId(), 0, "Delete");
/*
* MenuInflater inflater = getMenuInflater();
* inflater.inflate(R.menu.context_menu, menu);
*/
}
private void initComponents() {
inflater = ContextMenuActivity.this.getLayoutInflater();
list …
Run Code Online (Sandbox Code Playgroud) android listview android-layout android-listview android-inflate
我是快速编程的新手,我不知道如何定期调用方法.我有一个服务电话的演示应用程序,但我不知道如何定期调用它.
如何在不同线程的后台执行某些操作,如果它在主线程上执行则会阻止我的应用程序的UI.任何人都知道该怎么做?
即使它在后台打印NSLog也没关系.即使用户按下HOME按钮,我也希望运行以下内容.在我的viewController中我这样做了:
- (IBAction)btnStartClicked:(UIButton *)sender {
[NSThread detachNewThreadSelector:@selector(StartBGTask) toTarget:self withObject:nil];
}
-(void)StartBGTask{
[[[UIApplication sharedApplication] delegate] performSelector:@selector(startThread)];
}
Run Code Online (Sandbox Code Playgroud)
并在appDelegate.mi中有这个方法
-(void) startThread {
@autoreleasepool {
for (int i = 0; i < 100; i++) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"current progress %d", i);
});
[NSThread sleepForTimeInterval:1];
}
}
}
Run Code Online (Sandbox Code Playgroud)
它以1秒的间隔打印1到100之间的整数.
我正在尝试实现一个应用程序,当启动时,我的自定义视频录制屏幕自动启动视频录制,我自己的按钮停止录制和其他按钮.我所做的是设计按钮的布局,直到现在,但如何在后台添加视频录制屏幕..请帮助.
我想在Android操作栏上添加一个没有预选选项的下拉菜单.更确切地说,我希望箭头位于操作栏上应用程序的图标旁边.到目前为止,代码是:
protected void onCreate(Bundle savedInstanceState) {
.
.
.
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.logo_options,
android.R.layout.simple_spinner_dropdown_item);
actionBar.setListNavigationCallbacks(spinnerAdapter, null);
}
Run Code Online (Sandbox Code Playgroud)
如何摆脱操作栏上的文字?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/gray"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/darkgray"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/attenders"
android:layout_width="110dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="@color/gray"
android:layout_marginRight="8dp"
android:text="Attenders" />
<Button
android:id="@+id/send"
android:layout_width="110dp"
android:layout_height="40dp"
android:layout_marginLeft="8dp"
android:layout_gravity="center"
android:background="@color/gray"
android:text="Send IM" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的代码,但 dp 不适用于所有屏幕分辨率。建议请告诉我,如果我做错了什么