我在main.xml中有一个LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/mainLayout" >
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我制作了另一个XML文件,称为item_box.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/item_bg"
android:gravity="right" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:text="@string/item1"
android:textSize="30dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:gravity="right"
android:text="@string/number1"
android:textColor="@color/number_bg"
android:textSize="30dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
基本上,我想从代码中(以编程方式)执行的操作是将几个item_box.xml添加到main.xml中。我该怎么做?
Hy大家,
我需要帮助.我怎么检查属于linearlayout的视图?
我有一个ImageButton,我需要一个条件,验证是否属于linearlayout.这是一个简单的问题,但我很累,现在没有想到任何事情.我很感激你的帮助
有人可以帮忙吗?谢谢你的帮助
现在它垂直分裂...我希望它水平分割.我看过其他人说他们横向切割我无法区分......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个布局,我希望最后一个LinearLayout在最底部对齐.我试图设置重力,android:layout_marginbottom=0dp并且似乎没有人将它与底部对齐.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".ItemDetailActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="154dp" >
<ImageView
android:id="@+id/albumArt"
android:layout_width="140dp"
android:layout_height="138dp"
android:src="@drawable/stealyourface" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal|center"
android:orientation="vertical" >
<TextView
android:id="@+id/artistName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="@dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#E6E6E6" />
<TextView
android:id="@+id/showLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#E6E6E6" />
<TextView
android:id="@+id/showDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#E6E6E6" />
<TextView
android:id="@+id/runningSong"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#E6E6E6" />
</LinearLayout>
<TextView
android:id="@+id/currentlyPlaying"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#E6E6E6" />
</LinearLayout>
<ScrollView
android:id="@+id/ScrollView01" …Run Code Online (Sandbox Code Playgroud) 我试图把一个edittext和一个图像作为背景水平放在一个linearlayout按钮内但是我的按钮恰好被移动了一点,看起来很奇怪.我想使edittext和button从顶部和底部对齐.
<LinearLayout
android:id="@+id/footerlayout"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="3">
<EditText
android:id="@+id/textbox"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@drawable/textbox2"
android:gravity="top|left"
android:hint="Type to text"
android:layout_weight="2.5" />
<Button
android:id="@+id/sendbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/send2323"
android:gravity="center"
android:layout_weight="0.5"/>
<requestFocus />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 你的想法是编写一个活动,将谷歌地图api v2显示为一个片段,并在按钮上设置两个按钮,用于处理服务并在地图上生成标记.
问题是现在是否可以将地图片段放入定义和处理按钮的常规布局中,或者我必须将按钮放在另一个片段中?
目前,即使我通过android:height限制大小,地图也会覆盖整个屏幕
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/DarkGrey">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="410dp"
class="com.google.android.gms.maps.SupportMapFragment" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom">
<Button
android:id="@+id/buttonStopTracking"
android:text="@string/btn_stop_tracking"
android:layout_width="160dp"
android:layout_height="60dp"
android:textSize="20sp"
android:textStyle="bold"
/>
<Button
android:id="@+id/buttonCreatePoI"
android:text="@string/btn_create_PoI"
android:layout_width="160dp"
android:layout_height="60dp"
android:textSize="20sp"
android:textStyle="bold"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我有这个xml布局,但问题是,在滚动视图中,它的高度跨越整个屏幕并重叠底部线性布局(在它上面绘图).有没有办法,我可以让滚动视图高度仅达到底部的线性布局?我希望底部的2个按钮与屏幕底部对齐.
谢谢
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ActivityProfile" >
<ScrollView
android:id="@+id/scrollView1"
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:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/picture_avatar"
android:layout_width="90dp"
android:layout_height="310dp"
android:background="#bdbdbd"
android:src="@drawable/no_avatar" />
<TextView
android:id="@+id/textview_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="" />
</LinearLayout>
<TextView
android:id="@+id/textview_fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="" />
<TextView
android:id="@+id/textview_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:text="" />
<TextView
android:id="@+id/textview_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="" />
<TextView
android:id="@+id/textview_website"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="" />
<TextView
android:id="@+id/textview_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:text="" />
<TextView …Run Code Online (Sandbox Code Playgroud) 我有以下问题,如果我有一个扩展LinearLayout的类,如:
public class ExtendedSeekbarLayout extends LinearLayout { ..}
Run Code Online (Sandbox Code Playgroud)
我想将其他参数传递给我的版面,我该怎么做?我知道我可以拥有以下构造函数:
public ExtendedSeekbarLayout (Context context) {
super(context);
}
public ExtendedSeekbarLayout (Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
public ExtendedSeekbarLayout (Context context, AttributeSet attributeSet, int defStyle) {
super(context, attributeSet, defStyle);
}
Run Code Online (Sandbox Code Playgroud)
但我希望有类似的东西:
public ExtendedSeekbarLayout (Context context, AttributeSet attributeSet, int defStyle, int position) {
super(context, attributeSet, defStyle);
init(position);
}
Run Code Online (Sandbox Code Playgroud)
我不确定这是否可能,如果没有,那将是什么方式呢?
非常感谢和欢呼,pingu
尝试使用LinearLayout在底部对齐按钮,但是在TextView下面.
要在底部设置按钮,我正在使用android:layout_gravity="bottom"但仍未完成
LinearLayout xml
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_gravity="bottom"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Bottom" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我试图设置2个框架布局的宽度和高度,这是2个片段的容器,它们都是线性布局的子代。
但是,每当我使用
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(100,100);
Run Code Online (Sandbox Code Playgroud)
它导致类强制转换异常
java.lang.ClassCastException:android.widget.FrameLayout $ LayoutParams无法转换为android.widget.LinearLayout $ LayoutParams
android classcastexception android-linearlayout android-fragments android-framelayout
android ×9
class ×1
constructor ×1
extend ×1
fragment ×1
google-maps ×1
java ×1
orientation ×1
scroll ×1
view ×1
xml ×1