我想在列表视图的底部有一个按钮.
如果我使用relativeLayout/FrameLayout,它会对齐,但listView会变得非常紧张.
(在底部的按钮后面)

的FrameLayout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/btnButton"
android:text="Hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</FrameLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
RelativeLayout的:
<?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">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/btnButton"
android:text="Hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
以上两个代码只能像第一张图像一样工作.我想要的是第二张图片.
有人可以帮忙吗?
谢谢.
我相信Google建议开发人员使用AsyncTask.但是,我想知道它与使用"新线程"然后在性能和内存效率方面调用"RunOnUiThread"有何不同.
使用RunOnUithread的示例:
// some code #1
Thread t = new Thread("Thread1") {
@Override
public void run() {
// some code #2
runOnUiThread(new Runnable() {
public void run() {
// some code #3 (that needs to be ran in UI thread)
}
});
}
};
t.start();
Run Code Online (Sandbox Code Playgroud)
与
的AsyncTask:
onPreExecute() {
// some code #1
}
doInBackground() {
// some code #2
}
onPostExecute() {
// some code #3
}
Run Code Online (Sandbox Code Playgroud)
有什么优点/缺点?
编辑:
我不是在寻找像'更容易看到代码','方便开发人员'等答案.我实际上是在寻找幕后的技术差异.
例如,Paul Nikonowicz在下面的回答就是我想要的答案.(但AsyncTask的行为相同)
我一直在谷歌搜索,但很难找到制造商/型号使用哪个路径的SD卡/外部存储.
Environment.getExternalStorageDirectory()
我知道getExternalStorageDirectory()有时在某些设备上指向外部SD卡.
这是我发现的外部路径的一些常见路径(不确定哪个制造商使用哪个路径):
/emmc
/mnt/sdcard/external_sd
/mnt/external_sd
/sdcard/sd
/mnt/sdcard/bpemmctest
/mnt/sdcard/_ExternalSD
/mnt/sdcard-ext
/mnt/Removable/MicroSD
/Removable/MicroSD
/mnt/external1
/mnt/extSdCard
/mnt/extsd
/mnt/usb_storage <-- usb flash mount
/mnt/extSdCard <-- usb flash mount
/mnt/UsbDriveA <-- usb flash mount
/mnt/UsbDriveB <-- usb flash mount
Run Code Online (Sandbox Code Playgroud)
这些是我通过谷歌搜索找到的.
我需要扫描整个内部+外部存储器+ USB闪存驱动器以查找某个文件.如果我遗漏了任何路径,请添加到上面的列表中.如果有人知道每个制造商使用的路径,请与我们分享.
我知道如何使用颜色填充制作材质设计按钮:
style="@style/Widget.AppCompat.Button.Colored"
Run Code Online (Sandbox Code Playgroud)
并且没有边框的透明按钮:
style="@style/Widget.AppCompat.Button.Borderless.Colored"
Run Code Online (Sandbox Code Playgroud)
但是,有没有办法让Material Design设计成边框(透明内部)按钮?像下面的东西?
android button android-button material-design material-components-android
我可以获得总可用内存:
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
memoryInfo.availMem;
Run Code Online (Sandbox Code Playgroud)
但是,如何获得设备的总内存(RAM)?
我读过: 如何在Android中发现我的应用程序的内存使用情况?
它似乎没有添加pidMemoryInfo.getTotalPss()给我总内存.
当我单击按钮时,字体大小缩小为12.但结果是:

main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:background="#80ff0000"
android:text="@string/hello" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Java的:
public class FontSizeTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView text = (TextView) findViewById(R.id.test);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text.setTextSize(12);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
如何缩小textView的高度,使其仅包装实际字体?


如果您查看Android设置屏幕截图或FragmentsBC屏幕截图,PreferenceFragment中会有保证金.你怎么能摆脱它?
我尝试将PreferenceFragment宽度设置为fill_parent,但没有运气.
在我要求删除PreferenceActivity/PreferenceFragment的填充之前:
Android:如何最大化PreferenceFragment宽度(或摆脱保证金)?
这次我无法在标题文本之前调整边距/填充.(见下图).

有人有任何想法吗?
android {
enforceUniquePackageName = false
}
Run Code Online (Sandbox Code Playgroud)
"enforceUniquePackageName"适用于gradle版本:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将gradle版本更改为3.0.0
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
Could not set unknown property 'enforceUniquePackageName' for object of type com.android.build.gradle.AppExtension. Open File
Run Code Online (Sandbox Code Playgroud)
如果不推荐使用'enforceUniquePackageName'属性,那么替代选项会是什么?
我一直在等这个功能.
Android 2.3.3允许在没有root的情况下截取屏幕截图.
你能以编程方式截取截图吗?如果是这样的话?
或者只是手动(如Home + Power按钮),如Apple?
android ×10
preference ×2
alignment ×1
api ×1
button ×1
gradle ×1
layout ×1
listview ×1
margin ×1
material-components-android ×1
memory ×1
path ×1
performance ×1
screenshot ×1
sd-card ×1
textview ×1