在Android中,我们如何检测用户是否触摸按钮并拖出此按钮的区域?
我正在使用android数据绑定库.如果我想让视图可见,我可以写这样的东西:
<TextView
android:id="@+id/label_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@{habitListViewModel.message}"
app:visibility="@{habitListViewModel.hasError ? View.VISIBLE : View.GONE}" />
Run Code Online (Sandbox Code Playgroud)
是否有以类似(xml)方式绑定到swipeRefreshLayout的刷新属性的选项?
目前我通过调用setRefreshing(true/false)在代码中设置它,但是希望在xml中使它保持一致.
我想知道是否有人知道为自定义按钮生成xml选择器文件的工具.我有点累了创建按钮,将它们转换为.9.png文件,然后在xml中复制和粘贴自定义选择器...
我知道这些工具:
http://www.androidicongenerator.net/
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html
因为它们在生成资源/资源方面很方便,我想念选择4个图像并生成一个随时可用的选择器xml,它输出如下内容:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed -->
<item android:state_pressed="true" android:background="@drawable/img_pressed" />
<!-- focused -->
<item android:state_focused="true" android:background="@drawable/img_focussed" />
<!-- default -->
<item android:background="@drawable/img_default" />
</selector>
Run Code Online (Sandbox Code Playgroud)
我在考虑自己创造一个,但不敢相信没有人已经做过:)
谢谢
我非常喜欢添加到Android的AnimatedVectorDrawable功能.有没有很好的工具来创建这样的动画?
例如,任何创建动画的工具,如下所述:
编辑:
到目前为止,我已经找到了这些工具(这有点帮助):
android android-animation material-design android-vectordrawable
我有一个带开始按钮的简单屏幕.按下"开始"按钮后,我想转到带有SurfaceView的新屏幕以显示相机.
一切正常,但相机需要一段时间才能加载,这给了我一个黑屏.我想加载新的布局.并且在装载后启动相机...
因此,我在后台线程中完成所有相机加载,但仍然,我得到一个黑屏...这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/blue_bg">
<SurfaceView
android:id="@+id/surface_camera"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_below="@id/scan_header"
android:layout_above="@id/scan_footer">
</SurfaceView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的Activity中的方法,它加载新视图:
private void setContent()
{
setContentView(R.layout.scan)
Thread t = new Thread()
{
public void run()
{
final SurfaceView mSurfaceView = (SurfaceView)findViewById(R.id.surface_camera);
final SurfaceHolder mSurfaceHolder = mSurfaceView.getHolder();
try
{
cameraView = new CameraView();
mSurfaceHolder.addCallback(cameraView);
cameraView.setPictureListener(SunpluggedActivity.this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
} catch(Exception e)
{
Log.d(TAG, "Another exception");
e.printStackTrace();
}
}
};
t.start();
}
Run Code Online (Sandbox Code Playgroud)
为什么新的布局没有显示,直到线程完成加载相机?
编辑:我已经尝试Thread内的Thread.sleep(200)睡了一段时间...当我这样做时,新的布局显示出来,但相机永远不会启动......
介绍:
我有一个LinearLayout,它包含两个子LinearLayout,如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dual_pane"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="1.0">
<!-- Screen 1 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#ff0000"
android:layout_weight="1">
</LinearLayout>
<!-- Screen 2 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#ff6600"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
最初,我希望"屏幕1"可以使用所有屏幕宽度.因此,我的R.id.dual_pane的weightSum属性为1.0.这很好用!如果weightSum = 1.0,屏幕1占据整个屏幕!
加载一些资源后,我将R.id.dual_pane weighSum更改为2.0,这会导致屏幕1和屏幕2的屏幕宽度减少50%.这也很完美.当weightSum = 2.0时,两个屏幕占据宽度的50%.
问题:
我想为weightSum属性设置动画,所以我的Screen2将会滑入.我的目标是HoneyComb,所以minSDK版本是11,我想,使用新的ObjectAnimator框架,我可以很容易地动画这个属性,以获得一个很好的平滑效果.我验证了LinearLayout确实有getWeightSum()和setWeightSum()方法(我认为这是使用ObjectAnimator所必需的).
自己的努力:
这是我使用ObjectAnimator显示和隐藏Screen2的代码:
private void showScreen2()
{
//Not-animated will work...
//mDualPane.setWeightSum(2.0f);
// Now try to animate the weightSum
float ws = mDualPane.getWeightSum();
ObjectAnimator anim = ObjectAnimator.ofFloat(mDualPane, "weightSum", ws, 2.0f);
anim.setDuration(5000);
anim.start();
}
private void hideScreen2()
{
//Not-animated will work...
//mDualPane.setWeightSum(1.0f);
// Now …
Run Code Online (Sandbox Code Playgroud) 我被要求处理一个任务,其中将有两条线,我必须得到两条线的交点.两条线是ImageView
s,两条线都ImageView
可以被拖动,每当这两条线相交时,我必须得到那个交点.这是我到目前为止实现的代码:
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/xImg1" android:layout_width="100sp"
android:layout_height="100sp" android:layout_marginTop="50sp"
android:layout_marginLeft="10sp"
android:background="@drawable/line_6x10" />
<ImageView android:id="@+id/xImg2" android:layout_width="100sp"
android:layout_height="100sp" android:layout_marginTop="50sp"
android:background="@drawable/line_10x10" android:layout_marginLeft="200sp" />
Run Code Online (Sandbox Code Playgroud)
main.java
package sra.inter;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.RelativeLayout.LayoutParams;
public class Main extends Activity implements OnTouchListener {
private ImageView mImg1, mImg2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); …
Run Code Online (Sandbox Code Playgroud) 我正在使用 OpenCV 进行图像处理。我正在寻找一个人体,我想将其隔离(分段)。
目前,我能够找到身体的轮廓,并用多边形近似轮廓。接下来,我想在 cvWatershed 中使用该轮廓,以真正隔离身体。
有谁知道如何以向中心偏移的方式绘制轮廓?为了说明这一点,请参见下图。
蓝色:轮廓的多边形近似
红色:我想要的多边形,但无法找到。(上图中,我用的是photoshop...)
这是我查找和绘制当前轮廓的方法:
CvContourScanner scanner = cvStartFindContours(mask, pStorage, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
CvSeq* c;
CvSeq* polyContour;
int numCont = 0;
int perimScale = 4;
int contour_approx_level = 6;
while((c = cvFindNextContour(scanner)) != NULL)
{
CvSeq* c_new;
// Polygonal approximation
c_new = cvApproxPoly(c, sizeof(CvContour), pStorage, CV_POLY_APPROX_DP, contour_approx_level, 0);
// Create the new contour
cvSubstituteContour(scanner, c_new);
numCont++;
}
polyContour = cvEndFindContours(&scanner);
int i = 0;
for(i=0, c=polyContour; c!=NULL; c = c->h_next, i++)
{
cvDrawContours(pOutput, c, cvScalar(255,125,0), …
Run Code Online (Sandbox Code Playgroud) 我试图在一个按钮上打开另一个已安装的Android应用程序.应在调用应用程序的屏幕的一部分中打开新应用程序.
目前,我的代码创建了一个新的intent并在其中运行被调用的应用程序.调用应用程序消失了.这是我的代码:
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.ritwik.camera");
startActivity(intent);
}
});
Run Code Online (Sandbox Code Playgroud)
理想情况下,它应该作为同一屏幕的一部分打开,而不会使父(调用)应用程序边缘化.我怎么做?
我们在我们的 android 应用程序中使用 Firebase/Google 分析。每个事件都保存有大量额外信息(用户 ID、设备信息、时间戳、用户属性、地理位置……)。默认情况下,额外信息在那里,但我们不希望它被收集。
我们尝试了两件事:
1) 更新 Big Query Schema
从 Big Query 中删除不需要的列。不幸的是,Big Query 每天都会创建一个新的导出。所以我们需要知道这些字段来自哪里。我们不知道的东西。
2) 应用程序中的 DefaultParameters
尝试使用应用程序内部的默认参数,因此城市将始终为空。这是用户所在城市的示例
Bundle defaultValues = new Bundle();
defaultValues.putString("geo.city", null);
FirebaseAnalytics.getInstance(ctx).setDefaultEventParameters(defaultValues);
Run Code Online (Sandbox Code Playgroud)
不幸的是,我们仍然看到geo.city
在我们的 BigQuery 中填充了数据。
有没有办法改变默认收集的内容?
google-analytics firebase google-bigquery google-cloud-platform firebase-analytics
android ×8
approximate ×1
button ×1
contour ×1
data-binding ×1
drawing ×1
firebase ×1
gestures ×1
loading ×1
math ×1
opencv ×1
surfaceview ×1
xml-drawable ×1