有点问题.我想创建一个Android列表视图活动,列表中的所有项目都具有固定的高度.
所以,我的项目布局(thread_item.xml)如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="300dip"
>
<TextView android:id="@+id/thread_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[dummy]"
android:textSize="20dip"
android:textStyle="bold"
/>
<ImageView android:id="@+id/thread_first_image"
android:layout_below="@id/thread_item_title"
android:scaleType="centerInside"
android:maxWidth="100dip"
android:maxHeight="100dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true" />
<TextView
android:id="@+id/thread_item_preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/thread_first_image"
android:text="[dummy]"
android:textSize="15dip">
</TextView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我将根元素的layout_height设置为300dip,并期望所有项目具有相同的高度,但它们没有.当我运行应用程序时,它看起来像具有wrap_content值的高度.
此外,活动本身如下:
public class ThreadListActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
Code to get items from the storage.
*/
setListAdapter(new ThreadItemAdapter(this, R.layout.thread_item, itemsArray)));
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
/*Start …Run Code Online (Sandbox Code Playgroud) 您好我刚刚编辑了我的XML,我把幻灯片菜单代码放在我的XML中,但这是错误的.
<?xml version="1.0" encoding="utf-8"?>
<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:background="#ffffff" >
<ListView
android:id="@+id/menu_content_menulist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:cacheColorHint="@android:color/transparent"
android:divider="@null"
android:listSelector="@null"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mozaik.tangsel.side_menu_scroll.ScrollerLinearLayout
android:id="@+id/menu_content_side_slide_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="verti_
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/content_statis"
android:orientation="vertical"
android:background="@drawable/bg_app"
>
<include layout="@layout/layout_action_bar" />
<ScrollView
android:id="@+id/SV"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:background="@drawable/inbox_interface"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/ImageMozaikTangsel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip" />
</LinearLayout>
<LinearLayout
android:id="@+id/tabMozaikTangselLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</com.mozaik.tangsel.side_menu_scroll.ScrollerLinearLayout>
</RelativeLayout> …Run Code Online (Sandbox Code Playgroud) java android android-layout layoutparams android-relativelayout
在这段代码中,我想在两个ImageView的顶部之间画一条线.但是,在运行应用程序时,自定义视图在调用后显示为纯黑色invalidate().
这是我的代码:
public class ArrowView extends RelativeLayout {
public Paint paint;
public Bitmap eraser;
public Canvas cacheCanvas;
public float leftX;
public float leftY;
public float rightX;
public float rightY;
public boolean update = false;
public ImageView iv_leftArrow;
public ImageView iv_rightArrow;
private int w;
private int h;
LayoutInflater mInflater;
public ArrowView(Context context) {
super(context);
this.setWillNotDraw(false);
mInflater = LayoutInflater.from(context);
init();
}
public ArrowView(Context context, AttributeSet attrs) {
super(context, attrs);
this.setWillNotDraw(false);
mInflater = LayoutInflater.from(context);
init();
}
public ArrowView(Context context, AttributeSet attrs, …Run Code Online (Sandbox Code Playgroud) android android-custom-view android-canvas android-relativelayout
我在RelativeLayout中创建了一个可拖动的视图.但它似乎超越了RelativeLayout.
我只想在ViewGroup中创建一个View draggable
这个观点是draggable根据Screen.它可以超越RelativeLayout的界限.我如何限制它在RelativeLayout中保持可拖动.
CustomImageButton
public class ImageButtonCustom extends ImageButton implements View.OnTouchListener{
float dX, dY;
private RelativeLayout rootView;
private ImageButtonCustom imageButtonCustom;
private OnMoveListener onMoveListener;
public ImageButtonCustom(Context context,RelativeLayout rootView){
super(context);
this.rootView = rootView;
init();
}
public ImageButtonCustom(Context context) {
super(context);
init();
}
public ImageButtonCustom(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ImageButtonCustom(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init(){
imageButtonCustom = this;
setImageResource(R.drawable.upper_left);
setBackgroundColor(Color.TRANSPARENT);
setOnTouchListener(this);
/*RelativeLayout.LayoutParams …Run Code Online (Sandbox Code Playgroud) android android-custom-view ontouchlistener android-relativelayout
现在我已经使用线性布局创建了键盘布局,每个键是一个图像,例如"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
我正在尝试为我的视频播放器制作一个微调吧
trimmer_bar.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/thumbsBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
tools:background="@color/trimmerBarSelected">
<ImageView
android:id="@+id/leftThumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription=""
android:scaleType="fitStart"
android:src="@drawable/ic_left_thumb" />
<ImageView
android:id="@+id/rightThumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:contentDescription=""
android:scaleType="fitEnd"
android:src="@drawable/ic_right_thumb" />
</RelativeLayout>
<ImageView
android:id="@+id/progressIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="60dp"
android:layout_marginTop="3dp"
android:contentDescription=""
android:scaleType="centerCrop"
android:src="@android:drawable/btn_star_big_on" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
activity_video_viewer:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:orientation="vertical"
android:background="#a8c71c"
tools:context=".activities.VideoTrimmerActivity">
<com.tomatedigital.instagram.longstories.ui.TrimmerBar
android:id="@+id/trimmerBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/trimmerBarSelected"
/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
它的逻辑运作得很好:当用户触摸时,我检测到它是否在左拇指上的任何拇指和外壳上我调整了thumbBar的左边距,右边的情况我调整右边距...
由于两个imageview与边缘对齐,这种行为使它们移动......但实际上移动的是整个RelativeLayout
问题是甚至调整边距并移动图像视图,相对布局仍然显示边缘区域中的背景
忽略整个计算我使用以下方法设置边距:
this.thumbsBar= (RelativeLayout) findViewById(R.id.thumbsBar);
this.thumbsBarLayout = (LayoutParams) …Run Code Online (Sandbox Code Playgroud) 我很难在我的java代码中让两个文本视图相互叠加.这是我正在尝试的代码:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
layout = new RelativeLayout(this);
text1 = new TextView(this);
text1.setText("1");
text2 = new TextView(this);
text2.setText("2");
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams q = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
q.addRule(RelativeLayout.BELOW, layout.getId());
text1.setLayoutParams(q);
layout.addView(text1);
p.addRule(RelativeLayout.BELOW,text1.getId());
text2.setLayoutParams(p);
layout.addView(text2);
setContentView(layout);
}
Run Code Online (Sandbox Code Playgroud)
这将两个文本视图堆叠在同一行,但我希望TextView text2出现在TextView text1下面,所以在我的应用程序中,我希望以下内容显示为输出:
1
2
Run Code Online (Sandbox Code Playgroud)
我用"addRule"方法尝试了各种各样的东西,我不知道为什么这不起作用.我想知道如何在没有XML的情况下执行此操作,因为我计划构建一个方法库,可以构建一个可以通过编辑数组轻松调整的布局.
FrameLayout在Android中有什么用途?是否有针对其设计的特定方案?
在我的Android应用程序中,我有一个场景,我必须显示两个ImageView,一个在另一个.这是一个.png图像文件,在此图像上可以绘制9个补丁.
ViewGroup我应该为此目的使用哪个:RelativeLayout或FrameLayout?
我还想知道ViewGroup应该使用每个s 的不同场景.
android android-relativelayout android-viewgroup android-framelayout
我有一个ImageView并设置layout_height为"100dp",其layout_width设置为"wrap_content".
使用的可绘制的实际尺寸更大,为130dp(宽度)×215dp(高度).
当ImageView放置在a中时LinearLayout,如果我设置adjustViewBounds为true,它将获得根据drawable的纵横比和layout_width测量的宽度.
然而,放置在内部时RelativeLayout的ImageView得到相同的宽度可提拉(130dp),不管adjustViewBounds设置.
在这两种情况下,图像都会呈现相关性而不会失真,但ImageView的界限是不同的.
RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light">
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:src="@drawable/phone_orange"
android:contentDescription="@null" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

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="match_parent"
android:background="@android:color/background_light"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:src="@drawable/phone_orange" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

为什么ImageView这两种情况下的措施不同?有没有办法使ImageView行为始终像在LinearLayout情况下(用LinearLayout包装它工作,但它不是一个干净的解决方案)?
android android-layout android-imageview android-relativelayout
我有一个问题,我的ScrollView片段自动滚动到底部.因此,要解决这个问题,我已新增下列中的RelativeLayout行中建议这个答案:
android:descendantFocusability="blocksDescendants"
但是在添加这一行之后,textIsSelectable就停止了工作.如何添加两行?
这是XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:textSize="23sp"
android:text="The Beach Beneath the Street"
android:fontFamily="sans-serif-medium"
android:textColor="@color/black"
android:textIsSelectable="true"/>
<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:padding="15dp"
android:fontFamily="sans-serif-condensed"
android:lineHeight="25dp"
android:lineSpacingMultiplier="1"
android:lineSpacingExtra="6dp"
android:textSize="16sp"
android:text="Never add a RecyclerView or ListView to a scroll view"
android:textIsSelectable="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)