我创建了一个标签式活动,我使用android:layout_alignParentTop ="true"设置了位于屏幕顶部的名为android:id ="@ + id/adView"的AD.
运行应用程序后,我发现四个选项卡位于屏幕顶部.如何让AD位于Tab的上方?谢谢!
当前

我希望

activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
android:layout_alignParentTop="true"
ads:adUnitId="@string/ad_unit_id" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="@+id/adView"
android:layout_above="@+id/linearLayout1"
android:paddingTop="12dip"
android:paddingLeft="7dip"
android:paddingRight="7dip"
android:orientation="vertical" >
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager"
android:layout_width="wrap_content" android:layout_height="wrap_content"
tools:context=".MainActivity" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:weightSum="4" >
<Button
android:id="@+id/btnClose"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Close" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
fragment_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment">
<TextView android:id="@+id/section_label1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" /> …Run Code Online (Sandbox Code Playgroud) 我尝试从下面的链接测试关于屏幕记录的示例代码,我修改了一些代码以禁用录制音频.
http://www.truiton.com/2015/05/capture-record-android-screen-using-mediaprojection-apis/
我在Android Studio V1.3中测试代码,但是我收到以下错误,文件capture.mp4为空.
我不确定我是否必须在真正的手机上测试代码?你可以帮帮我吗 ?谢谢!
错误信息
09-22 06:41:50.250 2167-2167/? E/AndroidRuntime? FATAL EXCEPTION: main
Process: screencapture.truiton.com.myapplication, PID: 2167
java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
at screencapture.truiton.com.myapplication.MainActivity.onToggleScreenShare(MainActivity.java:93)
at screencapture.truiton.com.myapplication.MainActivity$1.onClick(MainActivity.java:55)
at android.view.View.performClick(View.java:4780)
at android.widget.CompoundButton.performClick(CompoundButton.java:120)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Run Code Online (Sandbox Code Playgroud)
源代码
package screencapture.truiton.com.myapplication;
public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
private static final int PERMISSION_CODE = 1;
private int mScreenDensity;
private MediaProjectionManager …Run Code Online (Sandbox Code Playgroud) 我已经阅读了Anko SQLite的文档.
我知道创建一个简单的RowParser可以通过这样做来完成 val rowParser = classParser<Person>()
classParser是Anko-SQLite源代码中定义的函数.
我怎么能得到一个简单的MapRowParser?
我是Kotlin的初学者,我使用代码A来定义一个复杂的类MDetail,并使用代码B来创建一个对象aMDetail1,它可以工作.
但数据结构是太糟糕了扩大,如果我有一个新的数据类如ScreenDef中MDetail 就像代码C,所有旧的代码必须rewriten.
对于包含某些类的复杂类,是否有良好的数据结构?我希望将来数据构建可以轻松扩展!
代码A.
data class BluetoothDef(val Status:Boolean=false)
data class WiFiDef(val Name:String, val Status:Boolean=false)
data class MDetail (
val _id: Long,
val bluetooth: BluetoothDef,
val wiFi:WiFiDef
)
Run Code Online (Sandbox Code Playgroud)
代码B.
var mBluetoothDef1= BluetoothDef()
var mWiFiDef1= WiFiHelper(this).getWiFiDefFromSystem()
var aMDetail1= MDetail(7L,mBluetoothDef1,mWiFiDef1)
Run Code Online (Sandbox Code Playgroud)
代码C.
data class BluetoothDef(val Status:Boolean=false)
data class WiFiDef(val Name:String, val Status:Boolean=false)
data class ScreenDef(val Name:String, val size:Long)
...
data class MDetail (
val _id: Long,
val bluetooth: BluetoothDef,
val wiFi:WiFiDef
val aScreenDef:ScreenDef
...
)
Run Code Online (Sandbox Code Playgroud)
以下代码基于 …
我已阅读https://developers.google.com/admob/android/quick-start?hl=en-US#import_the_mobile_ads_sdk
我需要使用代码A初始化MobileAds才能显示AdMob AD.
我有一些活动需要显示AD,我是否需要在我的所有活动中添加代码A?
此外,为什么AdMob广告即使我删除也能正确显示
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID")
Run Code Online (Sandbox Code Playgroud)
代码A.
import com.google.android.gms.ads.MobileAds;
class MainActivity : AppCompatActivity() {
...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID")
}
...
}
Run Code Online (Sandbox Code Playgroud) 我自定义了一个RecyclerView类,它将val backupItemList: List<MSetting>在代码B中显示Kotlin中的内容
现在我在RecyclerView类之外修改backupItemList的数据,我认为Code D会在UI中显示最新数据,但是我失败了,UI仍然显示旧数据.我必须使用Code C来显示最新数据.
代码D有什么问题?
代码A.
class UIMain : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_main)
allList= SettingHandler().getListAllSetting()
mRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayout.VERTICAL, false)
mCustomAdapter= CustomAdapter(allList)
mRecyclerView.adapter= mCustomAdapter
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
//Code C
if (resultCode == RESULT_OK) {
allList=SettingHandler().getListAllSetting()
mCustomAdapter= CustomAdapter(allList)
mRecyclerView.adapter= mCustomAdapter
mCustomAdapter.notifyDataSetChanged()
mCustomAdapter.setSelectedItem(selectedBackupItem)
}
//Code D
if (resultCode == RESULT_OK) {
allList=SettingHandler().getListAllSetting()
mCustomAdapter.setSelectedItem(selectedBackupItem)
}
}
}
Run Code Online (Sandbox Code Playgroud)
代码B.
class CustomAdapter (val backupItemList: List<MSetting>) : RecyclerView.Adapter<CustomAdapter.ViewHolder>() { …Run Code Online (Sandbox Code Playgroud) 在我调用代码 A 后,JobScheduler即使我关闭了 APP ,它也会继续运行。
但是一些定制的安卓系统可能JobScheduler在关闭APP的时候就清晰了。
如何检查是否以JobScheduler编程方式运行?
代码 A
private fun startScheduleRestore(mContext:Context){
logError("Start Server")
val interval=if (isDebug())
10*1000L
else
mContext.getInteger(R.integer.AutoRestoreInterval)*60*1000L
val mJobScheduler = mContext.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
val jobInfo = JobInfo.Builder(mContext.getInteger(R.integer.JobID), ComponentName(mContext, RestoreService::class.java))
.setPeriodic(interval)
.setPersisted(true)
.build()
mJobScheduler.schedule(jobInfo)
}
Run Code Online (Sandbox Code Playgroud)
代码 B
private fun stopScheduleRestore(mContext:Context){
logError("Stop Server")
val mJobScheduler = mContext.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
mJobScheduler.cancel(mContext.getInteger(R.integer.JobID))
}
Run Code Online (Sandbox Code Playgroud) 我是 Git 和 Github 的初学者,现在我通过在 Android Studio 上单击菜单项 VCS -> Git -> Push... 将更改提交到远程 Github 服务器。
图像是我的 Git 工具栏。只有一些按钮。
我希望 Push 按钮可以显示在主工具栏上,我该怎么办?
顺便说一句,我已经阅读了文章https://code.tutsplus.com/tutorials/working-with-git-in-android-studio--cms-30514,但我在 Android Studio 上找不到图像的步骤.
代码A需要navigator通过依赖注入实例化一个对象,所以作者使用代码B来实现它,你可以在这里看到它。
很奇怪这个类在Code C中通过依赖注入AppNavigatorImpl实现了类AppNavigator,所以我觉得Code D会很好用。
我可以用 @Inject lateinit var navigator: AppNavigatorImpl代替@Binds abstract fun bindNavigator(impl: AppNavigatorImpl): AppNavigator吗?
代码 A
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
@Inject lateinit var navigator: AppNavigator
...
}
Run Code Online (Sandbox Code Playgroud)
代码 B
@InstallIn(ActivityComponent::class)
@Module
abstract class NavigationModule {
@Binds
abstract fun bindNavigator(impl: AppNavigatorImpl): AppNavigator
}
Run Code Online (Sandbox Code Playgroud)
代码 C
class AppNavigatorImpl @Inject constructor(private val activity: FragmentActivity) : AppNavigator {
override fun navigateTo(screen: Screens) {
val fragment …Run Code Online (Sandbox Code Playgroud) 代码 A 来自Roman Y 回答的问题。
代码A调用with时可以正常工作background(appState)() {...},为什么不能去掉括号()?
但是代码 B 在调用 with 时失败了background(appState) {...},为什么?
而且更多的代码C在调用 with 时可以很好地工作 val aa=background(appState) aa{...},为什么呢?
代码A
@Composable
fun NiaApp(
windowSizeClass: WindowSizeClass,
appState: NiaAppState = rememberNiaAppState(windowSizeClass)
) {
NiaTheme {
background(appState)() {
Scaffold(
...
) { padding ->
}
}
}
}
@Composable
fun background(appState: NiaAppState): @Composable (@Composable () -> Unit) -> Unit =
when (appState.currentDestination?.route) {
ForYouDestination.route -> { content ->
NiaGradientBackground(content = content) }
else -> { content -> …Run Code Online (Sandbox Code Playgroud) lambda function-call higher-order-functions kotlin android-jetpack-compose