我有约束布局的问题,即文本在一个文本视图到达第二线不会下推被限制在它下面的另一个文本视图,直到该行的中间.
我已经构建了一个包含三个文本视图的简单布局.第一个文本视图位于左侧并具有设置宽度.第二个位于它的右边,在它和它的父母之间.第三个位于第一个的第二个和左侧.
在它(在"不重叠"的"O")的变化点似乎是当文本的长度填充在第一文本查看是不是有两条线:

那么如何更改此布局,以便即使我在屏幕左侧有文本视图,它也会在文本视图3到达两行时立即向下推?而不是将其推到第二行的一半.
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.testapp.myapplication.MainActivity">
<TextView
android:id="@+id/text_view_1"
android:layout_width="120dp"
android:layout_height="0dp"
android:background="@color/colorAccent"
android:text="Text View 1"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_view_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#22AA99"
android:text="Text View 2 Showing problem with overlap. Overlapping. Not O"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
app:layout_constraintLeft_toRightOf="@id/text_view_1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_view_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF00FF"
android:text="Text View 3"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/text_view_1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_view_2" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢.
getSupportActionBar()即使我之前在该方法中设置了支持操作栏,我也应该检查方法getSupportActionBar()吗?
在onCreate()我有三条线
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getIntent().getStringExtra(TITLE_KEY));
Run Code Online (Sandbox Code Playgroud)
Android Studio然后给我警告
"Method invocation may produce java.lang.NullPointerException"
Run Code Online (Sandbox Code Playgroud)
假设findViewById方法确实返回了一个有效的ToolBar对象,我是否仍然需要对该getSupportActionBar()方法进行null检查,或者只是忽略该警告是否安全?
刚刚使用kotlin开始使用Studio 3.0 Canary 3的新Android项目,并试图让它进行gradle项目同步.目前失败了
Error:Unsupported method: Dependencies.getAtoms().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
Run Code Online (Sandbox Code Playgroud)
任何人都知道这意味着什么以及如何解决它?
可能只需要改变某些东西的版本.
gradle包装:
#Mon Jun 19 08:02:32 BST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
Run Code Online (Sandbox Code Playgroud)
项目gradle
buildscript {
ext.kotlin_version = '1.1.2-5'
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha4' …Run Code Online (Sandbox Code Playgroud) 我在一个应用程序中使用支持操作栏并在2个设备中测试Nexus S和Nexus 7,我发现有关标签栏宽度,Nexus S标签栏填充宽度的不同结果,而nexus 7标签栏在左侧留有一些空间.我使用支持操作栏提供的默认主题,应用自定义主题不会影响操作栏,因为父样式必须是Theme.AppCompat.Light
清单中的活动
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)
类:
public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
ActionBar bar;
ViewPager pager;
TabsAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.pager);
bar = getSupportActionBar();
adapter = new TabsAdapter(getSupportFragmentManager());
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setHomeButtonEnabled(false);
pager.setAdapter(adapter);
pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// When swiping between different app sections, select the
// corresponding tab.
// …Run Code Online (Sandbox Code Playgroud) 我有一个库项目,包括使用Gradle的活动android.为了让它工作,我必须添加
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
Run Code Online (Sandbox Code Playgroud)
并为它添加存储库,如下所示:
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我在库项目中执行此操作,则会收到错误:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.michaelpardo:activeandroid:3.1.0-SNAPSHOT.
Searched in the following locations:
https://jcenter.bintray.com/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/maven-metadata.xml
https://jcenter.bintray.com/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.pom
https://jcenter.bintray.com/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.jar
file:/Users/user/AndroidSDK/extras/android/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/maven-metadata.xml
file:/Users/user/AndroidSDK/extras/android/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.pom
file:/Users/user/AndroidSDK/extras/android/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.jar
file:/Users/user/AndroidSDK/extras/google/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/maven-metadata.xml
file:/Users/user/AndroidSDK/extras/google/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.pom
file:/Users/user/AndroidSDK/extras/google/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.jar
Required by:
Condeco:app:unspecified > Condeco:common:unspecified
Run Code Online (Sandbox Code Playgroud)
我正在添加我的库模块,如下所示:
dependencies {
compile project(':common')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
Run Code Online (Sandbox Code Playgroud)
要删除此错误,我必须以相同的方式将存储库添加到主应用程序模块:
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,项目编译得很好.
我是否可以使用仅在库项目中定义的存储库来编译我的项目,而无需将存储库添加到主应用程序模块?我只想让库模块照顾好自己.