2016-12-31 192 views
1

Android Studio中版的位置:2.2.3Android Studio中:XML文件(设计选项卡)不能调整大小或TextView的

目标:在XML文件通过设计选项卡调整的TextView组件的大小。

我在做什么:在XML文件的设计选项卡中,在侧边栏中拖动Widgets文件夹中的“TextView”组件。然后,我抓住8个小盒子中的一个,并试图拉伸它(就像世界上大多数节目一样)。

预期输出:我希望“TextView”组件成为伸展组件时所勾画的新大小。

发生了什么:TextView的原点正好在父对象(content_main)的原点上,并且不会更改大小。

我可以在XML文件的文本选项卡中手动更改大小。话虽如此,我认为有一些错误的android:layout_width和高度= wrap_content。如果我将其更改为任何我想要的px,我会得到预期的输出。我该怎么做才能在设计选项卡中修改尺寸?

[编辑]适用于一切,我投入和container.xml设计选项卡(按钮,文本输入...)

的content.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:id="@+id/content_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:background="#006699" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.brandonwillis.myapplication.MainActivity" 
tools:showIn="@layout/activity_main"> 

<TextView 
    android:text="TextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentStart="true" /> 

</RelativeLayout> 

activity_main.xml中:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.brandonwillis.myapplication.MainActivity"> 

<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:minHeight="151dp" /> 

</android.support.design.widget.AppBarLayout> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    app:srcCompat="@android:drawable/ic_dialog_email" /> 

<include layout="@layout/content_main" 
    android:visibility="visible" /> 

</android.support.design.widget.CoordinatorLayout> 

视频我在做什么: https://www.youtube.com/watch?v=6NEtkrlnV6o

方面的问题(我可能找到其他地方),我怎样才能正确地格式化我的代码在StackOverflow?它显然失去了它的缩进。我打开代码括号并粘贴在我的代码中。

+0

这听起来像你拉约束,而不是规模的按钮。约束按钮位于视图的平面上,为了缩放,您只需要抓住“TextView”的角点。 –

+0

Android开发(第1天)非常新颖,那么这些约束和缩放按钮是什么?另外,我不知道你的意思是“平面的观点”。另外,如果我抓住角落,它会捕捉到原点,所以其他的东西一定是错的。我将在此期间研究这些事情的含义。谢谢 –

+0

为什么这个问题被低估?我尽可能以最精细的方式提出了问题,并发布了一段视频。我想我已经完成了这个网站。 –

回答

1

在content.xml中文件更改的RelativeLayout到绝对布局..

+0

非常感谢。你能解释这些布局之间的区别吗? –

0

在你TextView,尝试删除alignparent start and top,然后尝试设置heightwidth20dp,然后在设计再次缩放看看它是否工作。

+0

没有运气。它做同样的事情。 –

0

简短的回答:你不能这样做,因为wrap_content

龙答案 最初,知道什么是WRAP_CONTENT。 wrap_content自动分配视图的高度和宽度。如果你的textview有50个单词,或者它动态分配视图的高度和宽度。您尝试通过拉动手动更改高度和宽度,但不能这样做。更好的是你可以手动设置高度和宽度。

<TextView 
    android:text="TextView" 
    android:layout_width="200dp" <!-- Your Size here --> 
    android:layout_height="200dp" 
    android:id="@+id/textView" 
    /> 
+0

我有这个设置,它仍然做同样的事情。在这一点上,我想我只是在“文本”选项卡而不是设计选项卡上工作。无论如何,我从不喜欢DnD。 –

+0

没有别的途径,你必须使用“文本”标签来自定义textview属性...如果你学习如何使用文本标签设计,你永远不会使用设计标签来放置一个小部件... –

+0

@BrandonWillis如果你想要使textview大小为静态,例如200dp(宽度)x 48dp(高度),则必须在xml布局中的layout_width和layout_height属性中提及。 –

相关问题