我有我喜欢把我的屏幕的底部,并有其余内容调整大小以填充可用空间时,我看到我想要的确切的事情在广告加载,当我把它发生的AdMob广告横幅线性布局顶部的广告,然后将我的内容高度设置为fill_parent.这有可能反过来实现吗?当我使用fill_parent高度将广告置于我的内容下方时,由于没有足够的空间,因此无法显示.我有一个相对布局和底部边距的解决方案,以节省广告的空间,但我不喜欢广告加载前的黑色空间(如果它完全一样).有任何想法吗?
在CSS上我们可以写:
<div style="float:right"> Text1 </div>
<div style="float:right"> Text2 </div>
Run Code Online (Sandbox Code Playgroud)
通过这种方式Text1将出现在右边..
我试图对LinearLayout做同样的事情,View应该从右到左显示:
<LinearLayout android:id="@+id/linearLayout1" android:layout_gravity="right" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:weightSum="2" android:orientation="horizontal">
<!-- First Column should be on the right : Text1-->
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="right" android:gravity="right"
android:layout_weight="1">...</LinearLayout>
<!-- Second Column should be on the left : Text2 -->
<LinearLayout android:id="@+id/linearLayout3"
android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="right" android:gravity="right"
android:layout_weight="1">...</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢
我已经定义了一个扩展LinearLayout功能的自定义ViewGroup:
public class TestLayout extends LinearLayout {
public TestLayout(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.testlayout, this, true);
}
}
Run Code Online (Sandbox Code Playgroud)
它膨胀的布局(testlayout.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" android:gravity="center">
<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)
最后我在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" >
<my.test.namespace.TestLayout
android:id="@+id/testLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</my.test.namespace.TestLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在布局编辑器中查看我的main.xml时,eclipse会抛出一个错误: my.test.namespace.TestLayout无法实例化.
和堆栈跟踪:
android.content.res.Resources$NotFoundException: Could not resolve resource value: 0x7F030001.
at com.android.layoutlib.bridge.android.BridgeResources.throwException(BridgeResources.java:648)
at com.android.layoutlib.bridge.android.BridgeResources.getLayout(BridgeResources.java:270)
at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
at my.test.namespace.TestLayout.<init>(TestLayout.java:18) …Run Code Online (Sandbox Code Playgroud) 我想View在Android上创建自定义.我试图尽可能简单地创建它并创建了一个几乎为空的类MyView并在我LinearLayout的应用程序中使用它,但是应用程序在"强制关闭"开始时失败.我怎样才能做一个简单的定制View?根据构建自定义组件,View如果我不覆盖,则获取大小100x100 onMeasure().
public class MyView extends View {
public MyView(Context context) {
super(context);
}
}
Run Code Online (Sandbox Code Playgroud)
我用它来LinearLayout:
<view
class="com.example.MyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0" />
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
如果我使用itemon建议的构造函数和对超类的相应调用.然后"强制关闭"消失,但我LinearLayout的破坏,后面的组件MyView没有显示.
这是我的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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:background="#f00"
android:text="Hello"
/>
<view
class="com.example.MyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:background="#00f"
android:text="World"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 这就是我所拥有的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#FFFFFF">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#E30000"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_horizontal|center_vertical">
<TextView
android:id="@+id/TextView00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="20px"
android:textStyle="bold"
android:text="Something"
android:gravity="right|center_vertical"
/>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="right|center_vertical"
android:layout_gravity="center_vertical"
android:background="#E30000">
<Button
android:id="@+id/btnCalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/icon"
android:gravity="right|center_vertical"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想要这个:

因此水平中心对齐文本,垂直中心对齐按钮.
我错过了什么?我没有尝试过RelativeLayout,我更喜欢LinearLayout来解决这个问题.
有没有办法在水平线性布局中包装图像按钮?或者还有其他方法可以做以下事情吗?
我有六个图像按钮.假设这些按钮出现在中等分辨率设备中,如下所示:
Image button 1 | Image button 2 | Image button 3 | (1st row)
Image button 4 | Image button 5 | Image button 6 | (2nd row)
Run Code Online (Sandbox Code Playgroud)
我希望这些按钮出现在平板电脑或任何高分辨率设备中,如下所示:
Image button 1 | Image button 2 | Image button 3 | Image button 4 | (1st row)
Image button 5 | Image button 6 | (2nd row)
Run Code Online (Sandbox Code Playgroud)
或者像这样:
Image button 1 | Image button 2 | Image button 3 | Image button 4 | Image button 5 | …Run Code Online (Sandbox Code Playgroud) 我可以知道如何改变分频器的颜色LinearLayout吗?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:divider="?android:attr/dividerVertical"
android:dividerPadding="12dip"
android:showDividers="middle"
android:background="#ff2d2d2d" >
...
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我是否需要手动将Android SDK中的9个补丁图像复制到我的项目中,并定义我自己的属性来引用它?
我有这个代码:
FrameLayout game = new FrameLayout(this);
LinearLayout gameWidgets = new LinearLayout (this);
game.addView(gameWidgets);
Run Code Online (Sandbox Code Playgroud)
如何在FrameLayout的底部设置LinearLayout?
我正在尝试以编程方式将从HTML文件中选取的表单字段添加到LinearLayout.我在底部有一个下一个按钮,但它在显示屏上不断切断.我在平板电脑上尝试过,它仍然没有显示出来.
正如您所看到的,元素正在渲染,但最后一个元素由于某种原因而在屏幕上运行.
片段的XML:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".dataInput.PropertyInfoFragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_property_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="@+id/nextButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/next"
android:background="@color/colorPrimary"
android:textColor="@android:color/white"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
调用Activity的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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".dataInput.DataInputActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
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:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin" …Run Code Online (Sandbox Code Playgroud) android android-linearlayout android-fragments android-scrollview
现在我已经使用线性布局创建了键盘布局,每个键是一个图像,例如"Q","W","E"是不同的图像.
问题是,如何在上面添加提示图像?这个想法是,提示图像默认隐藏,当用户长按键时,会显示提示图像.
我有一套提示图像.有什么想法将它们添加到键盘布局?
非常感谢您的帮助.这是键盘布局参考
<LinearLayout
android:id="@id/training_keyboard"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:padding="5dp"
android:background="@color/colorBg">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="10"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/key1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:padding="2dp"
android:tag="?"
android:src="@drawable/keyboard_letter_r1_1" />
<ImageView
android:id="@+id/key2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:padding="2dp"
android:tag="?"
android:src="@drawable/keyboard_letter_r1_2" />
<ImageView
android:id="@+id/key3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:padding="2dp"
android:tag="?"
android:src="@drawable/keyboard_letter_r1_3" />
<ImageView
android:id="@+id/key4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:padding="2dp"
android:tag="?"
android:src="@drawable/keyboard_letter_r1_4" />
<ImageView
android:id="@+id/key5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:padding="2dp"
android:tag="?"
android:src="@drawable/keyboard_letter_r1_5" />
<ImageView
android:id="@+id/key6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_weight="1"
android:padding="2dp"
android:tag="?"
android:src="@drawable/keyboard_letter_r1_6" />
<ImageView
android:id="@+id/key7" …Run Code Online (Sandbox Code Playgroud) android android-layout android-softkeyboard android-linearlayout android-relativelayout
android ×10
admob ×1
center ×1
css-float ×1
custom-view ×1
java ×1
layout ×1
nine-patch ×1
view ×1