GirdLayout使一堆组件大小相等。这意味着最大尺寸的组件将定义所有组件的尺寸。是否可以根据每个组件的内部组件来确定其大小?
编辑:如果不可能,我怎样才能获得与 a 相同的效果,GridLayout但每个组件的大小基于其内部组件。
有人可以帮助我理解 Nativescript 中使用的网格布局,特别是 GridLayout 吗?auto 后面的(星号)实际上是什么意思?
<GridLayout rows="*, auto">
Run Code Online (Sandbox Code Playgroud)
然后我遇到了这个更令人困惑的例子:
<GridLayout rows="*, auto, auto, auto, 2*">
Run Code Online (Sandbox Code Playgroud)
我发现 Nativescript 的文档不太清楚。
我正在使用 RecyclerView 在网格布局中显示项目。下面是模拟器的图像和我需要实现的期望结果。左侧(执行)图像是我的模拟器上的输出,而右侧(所需)是我想要实现的输出。
活动布局 XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d3c3c3">
<include
android:id="@+id/toolBarIncluded"
layout="@layout/toolbar_new_layout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolBarIncluded"
android:orientation="vertical"
android:weightSum="1">
<RelativeLayout
android:id="@+id/recyclerAdView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="0.65"
android:background="#009688" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/recyclerAdView"
android:layout_gravity="center"
android:layout_weight="0.35"
android:background="#00000000"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:background="#00000000"
android:foregroundGravity="center" />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
列表项 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llGridItemLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="6dp"
android:background="@drawable/drawable_grid_item_background"
android:gravity="center"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:orientation="vertical">
<ImageView
android:id="@+id/ivItemIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/ic_new_receipt_wrong" />
<TextView
android:layout_marginTop="6dp"
android:id="@+id/tvItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1" …Run Code Online (Sandbox Code Playgroud) android grid-layout gridlayoutmanager android-recyclerview recyclerview-layout
我觉得这很容易,但找不到我的问题的解决方案:我只想要两个按钮,一个在另一个之上.两者都有屏幕宽度,都有半屏高度,所以它们填满了屏幕.我尝试了不同的RelativeLayout和GridView解决方案,但一切都出错了.
有没有人有我的解决方案?
我必须使用网格包布局在JFrame中设计按钮.这样所有系统的定位都可以相同.我使用以下代码,但我想分组按钮.
我想设计按钮,这样就可以创建三组,每组有4个按钮.
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class GridLayoutTest {
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("GridLayout Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(3, 2));
frame.add(new JButton("Button 1"));
frame.add(new JButton("Button 2"));
frame.add(new JButton("Button 3"));
frame.add(new JButton("Button 4"));
frame.add(new JButton("Button 5"));
frame.add(new JButton("Button 6"));
frame.add(new JButton("Button 7"));
frame.add(new JButton("Button 8"));
frame.pack();
frame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud) 这可能是一个愚蠢的问题,但在环顾世界各地的网站一段时间后,我找不到答案.
我正在为我的新网站使用twitter bootstrap的流体网格系统.我嘲笑主页的容器区域比twitter的默认1170px(1506px)宽.
1506px布局分解为:12列,每列98px(1176px),11个边距为30px(330px)
1176 + 300 = 1506.
那么有什么方法可以将这个宽度(1506)插入到twitter引导程序中,而不必检查一堆LESS和CSS?
我使用Gridlayout将4个元素放在一行中.首先,我有一个JPanel,一切正常.对于行数变大而我必须能够向下滚动的情况,我改变了一下.现在我添加JPanel了一个JScrollPane.我使用相同的代码,现在我只是将元素添加到视口中Jscrollpane,但现在我得到了这个例外Get java.lang.ClassCastException: layout of JScrollPane must be a ScrollPaneLayout: at javax.swing.JScrollPane.setLayout(Unknown Source),我不知道究竟是为什么.为什么Gridlayout不为人所知Jscrollpane?
这是代码:
public objectDetails() {
setTitle("LLI_MC_Solver");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = new JPanel();
contentPane.setLayout(new GridLayout());
setBounds(100, 100, 510, 401);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setVisible(true);
contentPane.setPreferredSize(new Dimension(500, 390));
JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setViewportBorder(new LineBorder(new Color(0, 0, 0), 2));
scrollPane.setBounds(10, 10, 474, 342);
scrollPane.setLayout(new GridLayout(0,4)); //Line which causes the error
scrollPane.setPreferredSize(new Dimension(465, 330));
contentPane.add(scrollPane);
JPanel view = (JPanel)scrollPane.getViewport().getView();
for(Values …Run Code Online (Sandbox Code Playgroud) 我想采取这样的数组:
var items = [1,2,3,4,5,6]
Run Code Online (Sandbox Code Playgroud)
并将其绑定在KnockoutJS中,以便呈现的输出为:
<div class="row">
<div class="col-md-4">1</div>
<div class="col-md-4">2</div>
<div class="col-md-4">3</div>
</div>
<div class="row">
<div class="col-md-4">4</div>
<div class="col-md-4">5</div>
<div class="col-md-4">6</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果不需要每三个项目关闭并打开一个新行,这将是直截了当的.任何建议,将不胜感激!
谢谢...
-ben
(这是在Java Swing上)
我创建了一个gridLayout(6,7),但看起来它更喜欢符合垂直要求的优先级高于水平.我的意思是,它总是有6行,无视7我希望它拥有的列.我想要它所以它总是有7列,我真的不关心行.(它的日历)
我怎么能做到这一点?
我正在尝试制作毕达哥拉斯定理计算器.现在,我正在尝试使用表单GridLayout.输入A,B或C侧的值,然后选中缺失侧的单选按钮.但是,我JTextField太大了,我希望它能与标签保持一致.我不想使用任何其他lyout经理.
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.*;
public class TriangleCalculator extends JFrame{
private JLabel sideALabel, sideBLabel, sideCLabel, triangleImage;
private JTextField sideAInput,sideBInput, sideCInput;
private JRadioButton sideAOption, sideBOption, sideCOption;
private JButton calculateButton, clearButton;
private JPanel buttonPane, mainPanel;
public TriangleCalculator(){
super("TriangleCalculator");
addComponents();
setSize(500, 500);
setVisible(true);
}
public void addComponents()
{
sideALabel = new JLabel("Enter the value of side A: ");
sideBLabel = new JLabel("Enter the value of side B: ");
sideCLabel = new JLabel("Enter the value of side C: …Run Code Online (Sandbox Code Playgroud) grid-layout ×10
java ×5
swing ×5
android ×2
awt ×1
css ×1
fullscreen ×1
javascript ×1
jframe ×1
jscrollpane ×1
knockout.js ×1
layout ×1
nativescript ×1