我有一个像这样的RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip">
<Button
android:id="@+id/negativeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:textColor="#ffffff"
android:layout_alignParentLeft="true"
android:background="@drawable/black_menu_button"
android:layout_marginLeft="5dip"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/positiveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:background="@drawable/blue_menu_button"
android:layout_marginRight="5dip"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我希望能够以编程方式设置positiveButton
相同的效果:
android:layout_centerInParent="true"
Run Code Online (Sandbox Code Playgroud)
我怎样才能以编程方式进行此操作?
事情很简单,但不能按原样运作.
我有一个文本文件作为原始资源添加.文本文件包含如下文本:
b)如果适用法律要求对软件提供任何担保,则所有此类担保的有效期限为交付日期后的第九十(90)天.
(c)虚拟定向,其经销商,经销商,代理商或雇员提供的任何口头或书面信息或建议均不构成保证或以任何方式增加此处提供的任何保证的范围.
(d)(仅限美国)有些州不允许排除默示担保,因此上述排除条款可能不适用于您.本担保赋予您特定的法律权利,您可能还拥有其他法律权利,这些权利因国家/地区而异.
在我的屏幕上,我有这样的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1.0"
android:layout_below="@+id/logoLayout"
android:background="@drawable/list_background">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/txtRawResource"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dip"/>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
读取原始资源的代码是:
TextView txtRawResource= (TextView)findViewById(R.id.txtRawResource);
txtDisclaimer.setText(Utils.readRawTextFile(ctx, R.raw.rawtextsample);
public static String readRawTextFile(Context ctx, int resId)
{
InputStream inputStream = ctx.getResources().openRawResource(resId);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
return null;
}
return byteArrayOutputStream.toString();
}
Run Code Online (Sandbox Code Playgroud)
文本得到了显示,但在每一行后我得到一个奇怪的字符[]如何删除该字符?我认为这是新线.
工作解决方案
public static …
Run Code Online (Sandbox Code Playgroud) 我有一个FrameLayout,其中我有2个控件: - 一个自定义视图,在其上绘制图像和一些文本 - 带有文本的textview
我想在FrameLayout中居中,但我无法做到.Texview的中心很好,当我看到它时,我的视图仍然在左侧.
<FrameLayout android:id="@+id/CompassMap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<view class="com.MyView"
android:id="@+id/myView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="gone"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="CENTERED" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
对Mathias来说,我在构造函数中没有做任何事情,这很简单
public class MyMapView extends View {
private int xPos = 0;
private int yPos = 0;
private Bitmap trackMap;
private Matrix backgroundMatrix;
private Paint backgroundPaint;
private Bitmap position;
private Matrix positionMatrix;
private Paint positionPaint;
public MyMapView(Context context) {
super(context);
init(context, null);
}
public MyMapView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
} …
Run Code Online (Sandbox Code Playgroud) 所以,看到新的Android L出来了,我说我应该试一试.我从SDK工具安装了新的ADT更新,然后从更新中安装.Eclipse重启后,我收到Android Dependencies无法加载的错误,因为无法找到\ android-sdk\tools\support\annotations.jar.
我检查了文件夹,但没有文件.
好吧,我对自己说,也许ADT更新不顺利所以看到新的日食4.4出来了我以为我可以做一个全新的安装.所以下载了eclipse 4.4,安装了ADT工具和android sdk ......我得到了同样的错误.
有想法该怎么解决这个吗 ?
在尝试导航组件之前,我曾经手动执行片段事务并使用片段标记来获取当前片段.
val fragment:MyFragment = supportFragmentManager.findFragmentByTag(tag):MyFragment
现在在我的主要活动布局中,我有类似的东西:
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/nav_host"
app:navGraph= "@navigation/nav_item"
android:name="androidx.navigation.fragment.NavHostFragment"
app:defaultNavHost= "true"
/>
Run Code Online (Sandbox Code Playgroud)
如何通过导航组件检索当前显示的片段?干
supportFragmentManager.findFragmentById(R.id.nav_host)
返回一个NavHostFragment
,我想检索我显示的'MyFragment`.
谢谢.
我在网上尝试了不同的方法,但无法使其正常工作.
Cursor cursor = sqlite.myDataBase.rawQuery("SELECT StartDate, EndDate FROM Tracks Where Id="+'"'+trackId+'"',null);
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = outputFormat.parse(cursor.getString(cursor.getColumnIndex("StartDate")));
Date endDate = outputFormat.parse(cursor.getString(cursor.getColumnIndex("EndDate")));
Run Code Online (Sandbox Code Playgroud)
通过这种方式,我可以获得良好格式的两个日期.现在我想找到之间的差异EndDate
,并Startdate
在几秒钟.
有什么建议?谢谢.
这是我的场景:
这可能是使用MediaMuxer实现的吗?很高兴收到有关此事的任何信息
我一直在寻找http://bigflake.com/mediacodec/#DecodeEditEncodeTest(谢谢@fadden),它说:
"解码帧并将其复制到ByteBuffer,
glReadPixels()
在Nexus 5上大约需要8ms,足够快,足以跟上30fps的输入速度,但将其作为PNG保存到磁盘所需的额外步骤是昂贵的(大约半秒钟) "
所以几乎1秒/帧是不可接受的.根据我的想法,一种方法是将每个帧保存为PNG,打开它,在其上添加位图叠加然后保存它.然而,这将花费大量时间来完成.
我想知道是否有办法做这样的事情:
在iOS上,我看到有一种方法可以将原始音频+原始视频+图像添加到容器中,然后对整个事物进行编码...
我应该切换到ffmpeg吗?ffmpeg的稳定性和兼容性如何?我是否冒着与Android 4.0+设备兼容的问题?有没有办法用ffmpeg来实现这个?我是这个领域的新手,还在做研究.
多年后编辑:
自问题以来已过去多年,并且ffmpeg在许可方面很难添加到商业软件中.这是如何演变的?较新版本的android在默认sdk上更有能力吗?
稍后编辑一段时间
我发布了一些负面投票信息作为答案,因此我将编辑原始问题.这是一个很棒的库,从我的测试中确实将水印应用于视频并使用进度回调进行处理,这使得向用户显示进度变得更加容易,并且还使用默认的android sdks.https://github.com/MasayukiSuda/Mp4Composer-android
该库使用Android MediaCodec API生成Mp4电影,并应用滤镜,缩放和旋转Mp4.
示例代码,可能如下所示:
new mp4Composer(sourcePath, destinationPath)
.filter(new GlWatermarkFilter(watermarkBitmap)
.listener(){
@Override
private void onProgress(double value){}
@Override
private void onCompleted(double value){
runOnUiThread( () ->{
showSneakbar
}
}
@Override
private void onCancelled(double value){}
@Override
private void onFailed(Exception e){}
}).start();
Run Code Online (Sandbox Code Playgroud)
在模拟器上进行测试,似乎在android 8+上正常工作,而在旧版本上生成黑色视频文件.但是,在真实设备上进行测试似乎有效.
目前的设置:
MainProject是一个图书馆计划
BranchProject是一个新项目,并以MainProject为参考
每当我调试并且MainProject中的文件处于焦点上时(实际上BranchProject只有图形和xml布局更改),"调试"窗口将打开一个只读的.class文件.我希望它打开.java文件,以便我可以直接编辑它.
从我到目前为止看来,Android的Instagram非常有限.我的场景很简单:允许用户编辑图片,当他点击发送时:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
Run Code Online (Sandbox Code Playgroud)
然后queryIntentActivities()
我搜索是否安装了Instagram.如果是,我发送要上传的图像的路径:
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + path to myfile.png"));
share.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
share.putExtra(Intent.EXTRA_SUBJECT, "Sample subject");
share.putExtra(Intent.EXTRA_TEXT, "Sample text");
share.putExtra(Intent.EXTRA_TITLE, "Sample title");
Run Code Online (Sandbox Code Playgroud)
结果:使用Instagram应用程序上传图像(当然,如果我已登录),但我无法为其添加标题.没有putExtra
任何影响.那么,有没有办法将标题添加为意图参数?
另一个问题是,是否可以打开填写了某个用户名的Instagram应用程序?
我的搜索中没有找到答案,有几个答案,但它们对我不起作用.
我在地图上有2个标记,我正在使用LatLngBounds构建器,以便让相机缩放到正确的缩放级别以包含它们.一切都按预期工作,除了一件事,当2个标记真的很接近时,地图非常非常放大,很好,这种缩放水平没有任何意义.
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(firstMarker.getPosition());
builder.include(secondMarker.getPosition());
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, markerPadding);
Run Code Online (Sandbox Code Playgroud)
有没有办法强制一定程度的变焦,之后相机不会变焦?这样可以避免地图放大/缩小.基本上我使用15.0f作为缩放级别.如果点太远,我希望变焦适合它们.如果点越来越近,我不希望缩放级别超过15.0f.