我正在设计我的XML,并且最初有一个与Action ToolBar重叠的Coordinator Layout.我阅读并发现添加应用程序:layout_behavior ="@ string/appbar_scrolling_view_behavior属性有助于解决此问题.
但是,在我的XML中,我仍然遇到协调器布局与预览屏幕上的底部按钮重叠的问题.我知道这些按钮实际上是在手机上,但我仍然感到困惑,为什么布局扩展到这些项目.看下面的图像与底部按钮重叠,我不记得在引入协调器布局之前看到这个:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.2" />
<LinearLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_weight="2">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.3">
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我启动了一个runnnable但没有将它分配给变量.我怎么阻止它?我知道它是removeCallbacksAndMessages()方法的组合,但由于我创建了一个匿名的runnable,我不知道传入此方法的参数:
mStartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
h = new Handler();
final int delay = 1000; //milliseconds
h.postDelayed(new Runnable() {
public void run() {
mUpdateRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int mNumberOfPollsForCurrentDay = (int) dataSnapshot.getChildrenCount();
Random r = new Random();
int randomPollInRangeOfCurrentDayNumberOfPolls = r.nextInt((mNumberOfPollsForCurrentDay + 1) - 1) + 1;
int numberOfPollAnswersAtRandomNumber = (int) dataSnapshot.child(String.valueOf(randomPollInRangeOfCurrentDayNumberOfPolls)).child(POLL_ANSWERS_LABEL).getChildrenCount();
Random rr = new Random();
int randomAnswerBasedFromRandomPollAnswerChoices = rr.nextInt((numberOfPollAnswersAtRandomNumber + 1) - 1) + 1;
mUpdateRef.child(String.valueOf(randomPollInRangeOfCurrentDayNumberOfPolls)).child(POLL_ANSWERS_LABEL).child(String.valueOf(randomAnswerBasedFromRandomPollAnswerChoices)).child("Vote_Count").runTransaction(new Transaction.Handler() {
@Override …Run Code Online (Sandbox Code Playgroud) 我有下面的 XML,并试图在单击时创建连锁反应。ListView 中每个项目的背景都是黑色,因此理想情况下,波纹效果会生成某种灰色:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/white" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/black"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/placeholder" />
<TextView
android:id="@+id/latest_item_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/white" />
Run Code Online (Sandbox Code Playgroud)
该代码创建以下内容。请注意,我想介绍棒棒糖之前和之后:
我正在尝试RecyclerView和GridLayoutManager。
我最终希望显示与此相同大小的图像,或者如果可能的话甚至是方形的:
GridLayoutManager使这成为可能的要素是什么?我是否修改用于填充的单个项目 XML RecyclerView?
我正在加载RecyclerView基于对Retrofit本地SQLite数据库的调用和存储的数据的。
屏幕旋转时,RecyclerView保持重置。此外,当我喜欢电影时(将电影添加到我的本地房间数据库中),在某些情况下,微调器无法与填充的数据对齐RecyclerView。下面是我的代码:
public class MainActivity extends AppCompatActivity {
private RecyclerView mMovieResults;
private MyAdapter mMovieResultsAdapter;
private String query;
private String mBaseURL;
private int lastFirstVisiblePosition;
//TODO: How is someone able to load my API Key if I am storing it
private ArrayList<String> mMovieURLS;
private ArrayList<Movie> mMovies;
private List<Movie> mMovieResultsList;
private static final String SPINNER_SELECTION = "SPINNER_SELECTION";
private boolean mIsFavoriteSelected;
private AppDatabase mDb;
private Spinner mSpinner;
private SharedPreferences mPrefs;
private SharedPreferences.Editor mPrefsEditor;
private …Run Code Online (Sandbox Code Playgroud) 我正在尝试为 UICollectioView 单元格创建材质波纹效果。对于 Android,有几种材料设计选项可以这样做,但对于 iOS,情况似乎并非如此。下面是我用作原型来填充 UICollectioView 的自定义单元格:
import UIKit
class PollCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var pollQuestion: UILabel!
}
Run Code Online (Sandbox Code Playgroud)
我在哪里初始化 CollectioViewCell:
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
prepareMenuButton()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Register cell classes
self.dataSource = self.collectionView?.bind(to: self.ref.child("Polls")) { collectionView, indexPath, snap in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! PollCell
//Here is where I am having issues
cell.pulseAnimation
/* …Run Code Online (Sandbox Code Playgroud) 我正在尝试将以下支持库添加到我的buid.gradle中:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 26
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 11
targetSdkVersion 26
}
signingConfigs {
release {
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
repositories {
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.7'
compile 'com.android.support:support-v7:26.0.0'
compile 'com.android.support:appcompat-v7:26.0.0'
compile 'com.android.support:cardview-v7:26.0.0'
compile 'com.melnykov:floatingactionbutton:1.1.0'
compile 'it.sephiroth.android.library.imagezoom:imagezoom:1.0.5'
//Apptentive
compile 'com.apptentive:apptentive-android:2.1.3@aar'
//compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.0.0'
}
Run Code Online (Sandbox Code Playgroud)
我收到错误,说明每个库"无法解决",然后是上面的每行代码.我希望能够继续使用最新的支持库来获得常规支持,appcompat和cardview.